示例#1
0
 public function testAsyncRun()
 {
     $testFileName = $this->testFileName;
     $this->assertFalse(file_exists($testFileName));
     \T4\Threads\Helpers::run(function ($text) use($testFileName) {
         sleep(10);
         file_put_contents($testFileName, $text);
     }, ['text' => 'Hello, world!']);
     sleep(5);
     $this->assertFalse(file_exists($testFileName));
     sleep(7);
     $this->assertTrue(file_exists($testFileName));
     $this->assertEquals('Hello, world!', file_get_contents($testFileName));
 }
示例#2
0
 /**
  * @param callable $callback
  * @param array $args
  * @throws \T4\Threads\Exception
  * @return int Child process PID
  */
 public function runLater(callable $callback, $args = [])
 {
     return Helpers::run($callback, $args);
 }