Last active
January 3, 2016 23:19
-
-
Save JosephMoniz/8534258 to your computer and use it in GitHub Desktop.
Purely functional event loop in php because why not?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$loop = PureLoop::loop(); | |
$ticked = $loop->flatMap(function(PureLoop $loop) { | |
return $loop->nextTick(function(PureLoop $loop) { | |
return StdIO::putStrLn("Hello from tick")->then(IO::of($loop)); | |
}); | |
}); | |
$timed = $ticked->flatMap(function(PureLoop $loop) { | |
return $loop->addTimer(new AsyncTimer(2, function(PureLoop $loop) { | |
return new More(StdIO::putStrLn("Hello from timer")->then(IO::of($loop))); | |
})); | |
}); | |
$ran = $timed->flatMap(function(PureLoop $loop) { | |
return $loop->runLoop(); | |
}); | |
$ran->unsafePerform(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment