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.

Last updated