dev-master
9999999-dev
The Requires
- jeremeamia/superclosure ~2.1
The Development Requires
0.1.0
0.1.0.0
The Requires
- jeremeamia/superclosure ~2.1
The Development Requires
Kyew is a thin layer on top of your existing queue package allowing you to push tasks to the queue and await the task completing., (*2)
Some examples where this could be useful include:, (*3)
$task = $kyew->async(function () { // Do some slow I/O operation return 'foo'; }); $response = $task->await(); // (string) "foo"
$google = $kyew->async(function () { return file_get_contents('http://google.com'); }); $bbc = $kyew->async(function () { return file_get_contents('http://bbc.co.uk'); }); // Both closures have already started executing in the background $google->await(); // (string) HTML source for Google's homepage $bbc->await(); // (string) HTML source for BBC's homepage
When tasks are passed to $task = $kyew->async($task)
, they are immediately handed off to the underlying queue package, along with an additional instruction to then store the task return value back into a persistance layer (eg. a database)., (*4)
On calling $task->await()
, we simply sit in a loop until either that value appears in the persistance layer, or until we reach the timeout threshold., (*5)
Kyew can be installed with Composer, (*6)
composer require adamnicholson/kyew
Kyew has two dependencies:, (*7)
Kyew\Queue
interface); used to hand jobs to your queueKyew\PubSub
interface; used to pass data between processesThe below example uses the InMemoryPubSub
and SynchronousQueue
queue - you should use implementations which suit your environment., (*8)
$pubsub = new Kyew\PubSub\InMemoryPubSub; $kyew = new Kyew\Kyew( $pubsub, new Kyew\Queue\SynchronousQueue($pubsub) ); $task = $this->kyew->async(function () { return 'Some return value!!!'; }); echo $task->await(); // string 'Some return value!!!'
Kyew::async(callable $task): Task
async
accepts a single callable as its only parameter and will return an instance of Task
., (*9)
$task = $kyew->async(function () { // Do some slow I/O operation return 'foo'; });
The callable is immediately handed to the queue library to be executed. The Task
instance will listen to the queue process and be notified when the callable has finished executing., (*10)
Task::await(): void
await
will block further code execution until the given Task has completed exectuing., (*11)
$response = $task->await(); echo $response; // (string) "foo"
IlluminateQueue
: Execute tasks in Laravel's (Illuminate) queue packageSynchronousQueue
: Execute tasks synchronously in the current process, mostly only used for testingDatabasePubSub
: Store task return values in a PDO
compatible SQL databaseRedisPubSub
: Store task return values in a redis serverInMemoryPubSub
: Store task return values in an in-memory PHP array, mostly only used for testingWe welcome any contributions to Kyew. They can be made via GitHub issues or pull requests., (*12)
Kyew is licensed under the MIT License, (*13)
Adam Nicholson - adamnicholson10@gmail.com, (*14)