Vapm
  • About
    • Why is it called unblocking?
    • Next update?
    • Credit
    • Info
  • System
    • runEventLoop()
    • runSingleEventLoop()
    • setTimeout()
    • setInterval()
    • fetch()
    • read()
    • time() & timeEnd()
  • Asynchronous
    • getId()
    • await()
  • Promise
    • c()
    • getId()
    • getFiber()
    • isJustGetResult()
    • getTimeOut()
    • getTimeStart()
    • getTimeEnd()
    • setTimeEnd()
    • canDrop()
    • getStatus()
    • getResult()
    • getReturn()
    • getCallback()
    • resolve() & reject()
    • then() & catch() & finally()
    • useCallbacks()
    • all()
    • allSettled()
    • any()
    • race()
    • Some common methods
  • CoroutineGen
    • runBlocking()
    • runNonBlocking()
    • Deferred
    • Deferred Await All
    • repeat() & delay()
    • Channel
      • Example about Channel
    • AwaitGroup
      • Example
    • Mutex
      • Example
    • Goroutine vs CoroutineGen
      • Concurrency
  • Thread
    • How do I create a thread?
    • How do I share data between threads?
    • Advanced Thread
  • Worker
    • Example
  • Stream
    • read()
    • write()
    • append()
    • delete()
    • create()
    • overWrite()
  • FAQ
    • Why System::runEventLoop() and System::runSingleEventLoop() ?
    • Do you want concurrency?
  • PocketMine-PMMP
Powered by GitBook
On this page
  1. System

setTimeout()

/**
 * This function is used to run a callback in the event loop with timeout
 */
public static function setTimeout(callable $callback, int $timeout): SampleMacro;

Similar to JavaScript, simply include a first callback, followed by milliseconds.

The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.

Example:

System::setTimeout(function() {
    echo "Hello World\n";
}, 5000);

Output:

Hello World // after 5 seconds.

As I said, as well as JavaScript next to setTimeout() there is a method to delete them via clearTimeout().

 /**
  * This function is used to clear the timeout
  */
 public static function clearTimeout(SampleMacro $sampleMacro): void;

Example:

$timeout = System::setTimeout(function() {
    echo "Hello World\n";
}, 5000);

System::clearTimeout($timeout);

Output:

Don't output anything the wallet deleted it.
PreviousrunSingleEventLoop()NextsetInterval()

Last updated 1 year ago