#!/usr/bin/env php receive())); try { $lock = (yield $this->acquire()); } catch (Exception $e) { echo $e; } print "Sleeping for 3 seconds...\n"; sleep(3); yield $this->send('Data sent from child.'); print "Sleeping for 2 seconds...\n"; sleep(2); yield 42; }); yield $context->send('Start data'); $lock = (yield $context->acquire()); printf("Cooperatively sleeping in parent for 2 seconds before releasing lock...\n"); yield Coroutine\sleep(2); $lock->release(); printf("Received the following from child: %s\n", (yield $context->receive())); printf("Thread ended with value %d!\n", (yield $context->join())); })->cleanup([$timer, 'stop'])->done(); Loop\run();