function increment(&$reindeers) { foreach ($reindeers as &$r) { tick($r); } $leads = getLeads($reindeers); foreach ($leads as $name) { $reindeers[$name]['points']++; } }
public function testNamespaceIsolation() { $i = 100; $a = 100; $b = 100; while (--$i > 0) { if (tick(50, 'a')) { $a--; } if (tick(25, 'b')) { $b--; } } $this->assertSame(50, $a); $this->assertSame(25, $b); }
<?php require __DIR__ . '/../vendor/autoload.php'; tick(3); // tick 1, false tick(3); // tick 2, false echo 'b'; xdebug_break(); echo 'a'; tick(3); // tick 3, true do { stack('a'); } while (!tick(5)); // tick 4, tick 5
function testTick() { $check = 0; setTimeout(function () use(&$check) { $check++; }, 1); nextTick(function () use(&$check) { $check++; }); tick(); $this->assertEquals(1, $check); }
/** * Block script execution indefinitely until the specified Promise resolves * * In the event of promise failure this method will throw the exception responsible for the failure. * Otherwise the promise's resolved value is returned. * * @param \Amp\Promise $promise The promise on which to wait * @throws \Exception if the promise fails * @return mixed Returns the eventual resolution result for the specified promise */ function wait(Promise $promise) { $isWaiting = true; $resolvedError = null; $resolvedResult = null; $promise->when(function ($error, $result) use(&$isWaiting, &$resolvedError, &$resolvedResult) { $isWaiting = false; $resolvedError = $error; $resolvedResult = $result; }); while ($isWaiting) { tick(); } if ($resolvedError) { throw $resolvedError; } return $resolvedResult; }
/** * * @throws Exception * @return mixed */ public function wait() { $hasEvents = true; while ($this->state === self::PENDING) { if (!$hasEvents) { throw new Exception('There were no more events in the loop. This promise will never be fulfilled.'); } $hasEvents = tick(true); } if ($this->state === self::FULFILLED) { return $this->value; } else { $reason = $this->value; if ($reason instanceof Exception || $reason instanceof \Exception) { throw $reason; } elseif (is_scalar($reason)) { throw new Exception($reason); } else { $type = is_object($reason) ? get_class($reason) : gettype($reason); throw new Exception('Promise was rejected with reason of type: ' . $type); } } }
break; case "load_user_forum_tabs": loadUserForumTabs(); break; case "load_thread_items": loadThreadItems(); break; case "load_debuguser": loadDebugUser(); break; case "tick": $uvs = ''; if (isset($_GET['uvs'])) { $uvs = $_GET['uvs']; } tick($uvs); break; case "post_action": postAction(); break; /*case "author_action": authorAction(); break; relic */ /* case "req_init": reqInit(); break; */ /* case "approve_all": approveAll(); break; */ /*case "author_action": authorAction();