@@ -320,6 +320,113 @@ function () {
320320 $ this ->loop ->run ();
321321 }
322322
323+ public function testFutureTick ()
324+ {
325+ $ called = false ;
326+
327+ $ callback = function ($ loop ) use (&$ called ) {
328+ $ this ->assertSame ($ this ->loop , $ loop );
329+ $ called = true ;
330+ };
331+
332+ $ this ->loop ->futureTick ($ callback );
333+
334+ $ this ->assertFalse ($ called );
335+
336+ $ this ->loop ->tick ();
337+
338+ $ this ->assertTrue ($ called );
339+ }
340+
341+ public function testFutureTickFiresBeforeIO ()
342+ {
343+ $ stream = $ this ->createStream ();
344+
345+ $ this ->loop ->addWriteStream (
346+ $ stream ,
347+ function () {
348+ echo 'stream ' . PHP_EOL ;
349+ }
350+ );
351+
352+ $ this ->loop ->futureTick (
353+ function () {
354+ echo 'future-tick ' . PHP_EOL ;
355+ }
356+ );
357+
358+ $ this ->expectOutputString ('future-tick ' . PHP_EOL . 'stream ' . PHP_EOL );
359+
360+ $ this ->loop ->tick ();
361+ }
362+
363+ public function testRecursiveFutureTick ()
364+ {
365+ $ stream = $ this ->createStream ();
366+
367+ $ this ->loop ->addWriteStream (
368+ $ stream ,
369+ function () use ($ stream ) {
370+ echo 'stream ' . PHP_EOL ;
371+ $ this ->loop ->removeWriteStream ($ stream );
372+ }
373+ );
374+
375+ $ this ->loop ->futureTick (
376+ function () {
377+ echo 'future-tick-1 ' . PHP_EOL ;
378+ $ this ->loop ->futureTick (
379+ function () {
380+ echo 'future-tick-2 ' . PHP_EOL ;
381+ }
382+ );
383+ }
384+ );
385+
386+ $ this ->expectOutputString ('future-tick-1 ' . PHP_EOL . 'stream ' . PHP_EOL . 'future-tick-2 ' . PHP_EOL );
387+
388+ $ this ->loop ->run ();
389+ }
390+
391+ public function testRunWaitsForFutureTickEvents ()
392+ {
393+ $ stream = $ this ->createStream ();
394+
395+ $ this ->loop ->addWriteStream (
396+ $ stream ,
397+ function () use ($ stream ) {
398+ $ this ->loop ->removeStream ($ stream );
399+ $ this ->loop ->futureTick (
400+ function () {
401+ echo 'future-tick ' . PHP_EOL ;
402+ }
403+ );
404+ }
405+ );
406+
407+ $ this ->expectOutputString ('future-tick ' . PHP_EOL );
408+
409+ $ this ->loop ->run ();
410+ }
411+
412+ public function testFutureTickEventGeneratedByTimer ()
413+ {
414+ $ this ->loop ->addTimer (
415+ 0.001 ,
416+ function () {
417+ $ this ->loop ->futureTick (
418+ function () {
419+ echo 'future-tick ' . PHP_EOL ;
420+ }
421+ );
422+ }
423+ );
424+
425+ $ this ->expectOutputString ('future-tick ' . PHP_EOL );
426+
427+ $ this ->loop ->run ();
428+ }
429+
323430 private function assertRunFasterThan ($ maxInterval )
324431 {
325432 $ start = microtime (true );
0 commit comments