Andika Saputra
Andika Saputra

Reputation: 31

How to use Revolt\EventLoop?

How to run below script using Revolt\EventLoop

use Amp\Loop;
Loop::Run(static function() {
    echo "Callback function executed!" . PHP_EOL;
})

Im tried this code but it return blank response

use Revolt\EventLoop;
EventLoop::run(static function() {
    echo "Callback function executed!" . PHP_EOL;
});

Please help me, thank you!

Upvotes: 2

Views: 135

Answers (1)

DrLightman
DrLightman

Reputation: 673

Try this way:

require __DIR__ . '/vendor/autoload.php';

use Revolt\EventLoop;

EventLoop::defer(function(): void {
    echo "Callback function executed!" . PHP_EOL;
});

EventLoop::run();

Your mistake was to pass the callback to ::run() which as far as I know it doesn't accept any argument, either in AMPHP or EventLoop.

ref: Revolt's EventLoop timers.

Upvotes: 0

Related Questions