本文整理汇总了PHP中React\EventLoop\Factory::stop方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::stop方法的具体用法?PHP Factory::stop怎么用?PHP Factory::stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\EventLoop\Factory
的用法示例。
在下文中一共展示了Factory::stop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Runs the WebSocket client.
*
* @return void
*/
public function run()
{
$this->wsfactory->__invoke($this->gateway)->then(function (WebSocketInstance $ws) {
$this->ws = $ws;
$ws->on('message', function ($data, $ws) {
$this->emit('raw', [$data, $this->discord]);
$data = json_decode($data);
if (!is_null($handler = $this->handlers->getHandler($data->t))) {
$handler = new $handler();
$handlerData = $handler->getData($data->d, $this->discord);
$newDiscord = $handler->updateDiscordInstance($handlerData, $this->discord);
$this->emit($data->t, [$handlerData, $this->discord, $newDiscord]);
$this->discord = $newDiscord;
}
if ($data->t == Event::READY) {
$tts = $data->d->heartbeat_interval / 1000;
$this->loop->addPeriodicTimer($tts, function () use($ws) {
$this->send(['op' => 1, 'd' => microtime(true) * 1000]);
});
$content = $data->d;
// set user settings obtain guild data etc.
// user client settings
$this->discord->user_settings = $content->user_settings;
// guilds
$guilds = new Collection();
foreach ($content->guilds as $guild) {
$guildPart = new Guild(['id' => $guild->id, 'name' => $guild->name, 'icon' => $guild->icon, 'region' => $guild->region, 'owner_id' => $guild->owner_id, 'roles' => $guild->roles, 'joined_at' => $guild->joined_at, 'afk_channel_id' => $guild->afk_channel_id, 'afk_timeout' => $guild->afk_timeout, 'large' => $guild->large, 'features' => $guild->features, 'splash' => $guild->splash, 'emojis' => $guild->emojis], true);
$channels = new Collection();
foreach ($guild->channels as $channel) {
$channelPart = new Channel(['id' => $channel->id, 'name' => $channel->name, 'type' => $channel->type, 'topic' => $channel->topic, 'guild_id' => $guild->id, 'position' => $channel->position, 'last_message_id' => $channel->last_message_id, 'permission_overwrites' => $channel->permission_overwrites], true);
$channels->push($channelPart);
}
$guildPart->setCache('channels', $channels);
// preload
$guildPart->getBansAttribute();
// guild members
$members = new Collection();
foreach ($guild->members as $member) {
$memberPart = new Member(['user' => $member->user, 'roles' => $member->roles, 'mute' => $member->mute, 'deaf' => $member->deaf, 'joined_at' => $member->joined_at, 'guild_id' => $guild->id, 'status' => 'offline', 'game' => null], true);
// check for presences
foreach ($guild->presences as $presence) {
if ($presence->user->id == $member->user->id) {
$memberPart->status = $presence->status;
$memberPart->game = $presence->game;
}
}
$members->push($memberPart);
}
$guildPart->setCache('members', $members);
$guilds->push($guildPart);
}
$this->discord->setCache('guilds', $guilds);
// after we do everything, emit ready
$this->emit('ready', [$this->discord]);
}
});
$ws->on('close', function ($ws) {
$this->emit('close', [$ws, $this->discord]);
});
$ws->on('error', function ($error, $ws) {
$this->emit('error', [$error, $ws, $this->discord]);
});
if (!$this->sentLoginFrame) {
$this->sendLoginFrame();
$this->sentLoginFrame = true;
$this->emit('sent-login-frame', [$ws, $this->discord]);
}
}, function ($e) {
$this->emit('connectfail', [$e]);
$this->loop->stop();
});
$this->loop->run();
}