mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
Merge branch 'psr' of https://github.com/lyrixx/amp into lyrixx-psr
This commit is contained in:
commit
24acba4486
@ -2,7 +2,6 @@
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Amp\ReactorFactory;
|
||||
use Amp\Reactor;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ Amp\run(function() {
|
||||
// garbage collect resources associated with one-time events after they finish executing.
|
||||
Amp\immediately($ticker);
|
||||
|
||||
// Execute every $msInterval milliseconds until the resulting $watcherId is cancelled.
|
||||
// Execute every $msInterval milliseconds until the resulting $watcherId is canceled.
|
||||
// At some point in the future we need to cancel this watcher or our program will never end.
|
||||
$repeatingWatcherId = Amp\repeat($ticker, $msInterval = 1000);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Amp\Reactor;
|
||||
use Amp\ReactorFactory;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
@ -28,7 +27,7 @@ Amp\run(function(Reactor $reactor) {
|
||||
}, $msDelay = 5000);
|
||||
|
||||
// After about five seconds the program will exit on its own. Why? This happens because in
|
||||
// that time frame we will have cancelled the repeating watcher we registered using repeat()
|
||||
// that time frame we will have canceled the repeating watcher we registered using repeat()
|
||||
// and the two one-off events (immediately() + once()) are automatically garbage collected
|
||||
// by the Reactor after they execute.
|
||||
});
|
||||
|
@ -19,12 +19,11 @@ class Client {
|
||||
|
||||
|
||||
/**
|
||||
* A simple TCP server that broadcasts the current time once per second to all connected clients
|
||||
* A simple TCP server that broadcasts the current time once per 3 seconds to all connected clients
|
||||
*/
|
||||
class Server {
|
||||
private $reactor;
|
||||
private $clients = [];
|
||||
private $timeBroadcastWatcher;
|
||||
private $ioGranularity = 8192;
|
||||
|
||||
public function __construct(Amp\Reactor $reactor = null) {
|
||||
@ -47,7 +46,7 @@ class Server {
|
||||
});
|
||||
|
||||
// Let's schedule a broadcast of the current time to all connected sockets every three seconds
|
||||
$this->timeBroadcastWatcher = $this->reactor->repeat(function() {
|
||||
$this->reactor->repeat(function() {
|
||||
$this->broadcastTime();
|
||||
}, $msInterval = 3000);
|
||||
|
||||
@ -97,7 +96,7 @@ class Server {
|
||||
if ($data == '' && $this->isSocketDead($client->socket)) {
|
||||
$this->unloadClient($client);
|
||||
} else {
|
||||
printf("Data rcvd from client %d: %s\n", $client->id, $data);
|
||||
printf("Data received from client %d: %s\n", $client->id, $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Process signals are "watchable" events just like timers and stream IO
|
||||
* availability. SignalReactor::onSignal() returns a unique watcher ID that
|
||||
* may be disabled/enabled/cancelled like any other watcher.
|
||||
* may be disabled/enabled/canceled like any other watcher.
|
||||
*
|
||||
* The available signal number constants vary by operating system, but you
|
||||
* can see the possible signals in your PHP install with the following
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
(new Amp\UvReactor)->run(function($reactor) {
|
||||
(new Amp\UvReactor)->run(function(Amp\Reactor $reactor) {
|
||||
// Let's tick off output once per second so we can see activity.
|
||||
$reactor->repeat(function() {
|
||||
echo "tick: ", date('c'), "\n";
|
||||
|
@ -9,7 +9,7 @@ define('SERVER_ADDRESS', '127.0.0.1:1337');
|
||||
* echo server example
|
||||
* 1. Connect to 127.0.0.1 at port 1337 from various terminals;
|
||||
* 2. Type in anything and press ENTER;
|
||||
* 3. Reactor will asyncronously read from client and broadcast to others.
|
||||
* 3. Reactor will asynchronously read from client and broadcast to others.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -106,7 +106,7 @@ class Server {
|
||||
if ($data == '' && $this->isSocketDead($client->socket)) {
|
||||
$this->unloadClient($client);
|
||||
} else {
|
||||
printf("Data rcvd from client %d: %s\n", $client->id, $data);
|
||||
printf("Data received from client %d: %s\n", $client->id, $data);
|
||||
$this->broadcast($client, "{$client->id} said: {$data}\n");
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
interface SignalReactor extends Reactor {
|
||||
|
||||
/**
|
||||
* React to process control signals
|
||||
*
|
||||
* @param int $signo The signal number to watch for
|
||||
* @param callable $onSignal
|
||||
* @return int Returns a unique integer watcher ID
|
||||
*/
|
||||
public function onSignal($signo, callable $onSignal);
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace Amp;
|
||||
|
||||
interface SignalReactor extends Reactor {
|
||||
|
||||
/**
|
||||
* React to process control signals
|
||||
*
|
||||
* @param int $signo The signal number to watch for
|
||||
* @param callable $onSignal
|
||||
* @return int Returns a unique integer watcher ID
|
||||
*/
|
||||
public function onSignal($signo, callable $onSignal);
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ namespace Amp;
|
||||
|
||||
/**
|
||||
* A "safe" Struct class for public property aggregators
|
||||
*
|
||||
*
|
||||
* This class is intended to make using public properties a little safer by throwing when
|
||||
* nonexistent property names are read or written. All property aggregation classes in the
|
||||
* Amp library descend from Struct somewhere in their inheritance heirarchies.
|
||||
* Amp library descend from Struct somewhere in their inheritance hierarchies.
|
||||
*/
|
||||
abstract class Struct {
|
||||
final public function __get($property) {
|
||||
|
@ -7,7 +7,6 @@ namespace Amp;
|
||||
* the Promisor that created it.
|
||||
*/
|
||||
class Unresolved implements Promise {
|
||||
private $isWaiting = false;
|
||||
private $isResolved = false;
|
||||
private $watchers = [];
|
||||
private $whens = [];
|
||||
|
@ -246,7 +246,6 @@ function all(array $promises) {
|
||||
$results = [];
|
||||
$remaining = count($promises);
|
||||
$promisor = new Future;
|
||||
$isResolved = false;
|
||||
|
||||
foreach ($promises as $key => $resolvable) {
|
||||
if (!$resolvable instanceof Promise) {
|
||||
|
Loading…
Reference in New Issue
Block a user