Skip to content

Commit

Permalink
Switch to use the global event-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Apr 18, 2021
1 parent 9fc5844 commit 9e4d880
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 87 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": "^7.4",
"dragonmantank/cron-expression": "^3.1",
"react/event-loop": "^1.1",
"react/event-loop": "dev-global-event-loop-accessor-part-four as 1.2.0",
"react/promise": "^2.7",
"thecodingmachine/safe": "^1.3",
"wyrihaximus/constants": "^1.6",
Expand All @@ -31,6 +31,12 @@
"WyriHaximus\\Tests\\React\\Cron\\": "tests/"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wyrihaximus-labs/event-loop"
}
],
"scripts": {
"post-install-cmd": [
"composer normalize"
Expand Down
124 changes: 79 additions & 45 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?php

use React\EventLoop\Factory;
use React\EventLoop\Loop;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;
use WyriHaximus\React\Action;
use WyriHaximus\React\Cron;

require 'vendor/autoload.php';

$loop = Factory::create();

Cron::createHighPrecision(
$loop,
new Action(
Cron::create(
new Cron\Action(
'Hour', // Identifier used for mutex locking locking
1, // TTL for Mutex Locking (usually a few times the maximum time this cron should take)
'@hourly', // The cron expression used to schedule this action
function (): PromiseInterface { // The callable ran when this action is due according to it's schedule
echo 'Another hour has passed!', PHP_EOL;

return resolve(true); // This callable MUST return a promise, which is used for releasing the mutex lock
}
),
new Action(
new Cron\Action(
'Minute',
300,
'* * * * *',
function (): PromiseInterface {
echo 'Another minute has passed!', PHP_EOL;
Expand All @@ -32,4 +31,4 @@ function (): PromiseInterface {
)
);

$loop->run();
Loop::get()->run();
Loading

0 comments on commit 9e4d880

Please sign in to comment.