1abbaa11e42d264dacaf4478607f1f6d49ea2bb2
4 require_once __DIR__
."/../vendor/autoload.php";
7 use Amp\Loop
as AmpLoop
;
9 $log = new Monolog\
Logger("seekat");
10 $log->pushHandler((new Monolog\Handler\
StreamHandler(STDERR
))->setLevel(Monolog\Logger
::INFO
));
12 $cli = new http\
Client("curl", "seekat");
14 "use_eventloop" => new class($cli, AmpLoop
::get()) implements http\Client\Curl\User
{
21 function __construct(http\Client
$client, AmpLoop\Driver
$driver) {
22 $this->client
= $client;
23 $this->driver
= $driver;
28 function run($socket = null, int $action = null) {
30 $remaining = ($this->runcb
)($this->client
, $socket, $action);
32 $remaining = ($this->runcb
)($this->client
);
40 if (!$this->driver
->getInfo()["running"]) {
46 throw new BadMethodCallException(__FUNCTION__
);
48 function wait(int $timeout_ms = null) {
50 throw new BadMethodCallException(__FUNCTION__
);
52 function timer(int $timeout_ms = null) {
54 $this->driver
->cancel($this->timeout
);
57 $this->timeout
= $this->driver
->delay($timeout_ms, function() {
63 $this->driver
->cancel($this->timeout
);
64 $this->timeout
= null;
67 function socket($socket, int $poll) {
68 foreach ((array) $this->driver
->getState((string) $socket) as $id) {
69 $this->driver
->disable($id);
75 $id = $this->driver
->onReadable($socket, function($id, $socket) {
76 $this->run($socket, self
::POLL_IN
);
78 $this->driver
->setState((string) $socket, $id);
81 $id = $this->driver
->onWritable($socket, function($id, $socket) {
82 $this->run($socket, self
::POLL_OUT
);
84 $this->driver
->setState((string) $socket, $id);
86 case self
::POLL_INOUT
:
88 $this->driver
->onReadable($socket, function($id, $socket) {
89 $this->run($socket, self
::POLL_IN
);
91 $this->driver
->onWritable($socket, function($id, $socket) {
92 $this->run($socket, self
::POLL_OUT
);
95 $this->driver
->setState((string) $socket, $id);
97 case self
::POLL_REMOVE
:
98 foreach ((array) $this->driver
->getState((string) $socket) as $id) {
99 $this->driver
->cancel($id);
101 $this->driver
->setState((string) $socket, null);
107 $api = new API(API\Future\amp
(), [
108 "Authorization" => "token ".getenv("GITHUB_TOKEN")
109 ], null, $cli, $log);
111 AmpLoop
::run(function() use($api) {
112 list($m6w6, $seekat) = yield
[$api->users
->m6w6(), $api->repos
->m6w6
->seekat()];
113 printf("Hi, my name is %s!\n", $m6w6->login
);
114 printf("Have fun with %s; %s!\n", $seekat->name
, $seekat->description
);