Haxe Forum > I just implemented continuation
-
杨博 Aug 13 at 07:35
Hello everyone, I am glad to introduce my work this weekend: continuation for Haxe.
The project is at https://github.com/Atry/haxe-continuation.
Usage
If a function's last parameter is a callback function, it is an asynchronous function. haxe-continuation enable you to write an synchronous function in continuation-passing style (CPS).You can use Continuation.cpsFunction to write such a CPS asynchronous function. In Continuation.cpsFunction, async is a keyword to invoke other async functions. In async, You need not to explicitly pass a callback function. Instead, the code after async will be captured as the callback function used by the callee.
import com.dongxiguo.continuation.Continuation; class Sample { static var sleepOneSecond = callback(haxe.Timer.delay, _, 1000); public static function main() { Continuation.cpsFunction(function asyncTest():Void { trace("Start continuation."); for (i in 0...10) { async(sleepOneSecond); trace("Run sleepOneSecond " + i + " times."); } trace("Continuation is done."); }); asyncTest(function() { trace("Handler without continuation."); }); } }
See https://github.com/Atry/haxe-continuation/blob/master/tests/TestContinuation.hx for more samples.Installation
I have upload to haxelib. To install, type following command in shell:
haxelib install continuation
I guess the NodeJS guys may interest on my project.
< Prev
| Page 1 / 1 |
Next >