Created
December 18, 2014 12:35
-
-
Save cambiata/c40e097f1e4d98c130e2 to your computer and use it in GitHub Desktop.
Example use of tink.core.Future in UFront controllers
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
import tink.core.Error; | |
import tink.core.Future; | |
import tink.core.Outcome; | |
import ufront.web.result.ContentResult; | |
class AsyncTestController extends ufront.web.Controller { | |
@:route('/async') public function async() return simulatedAsyncProcess(); | |
function simulatedAsyncProcess(): Surprise<ContentResult, Error> { | |
var f = Future.trigger(); | |
// simulated async processing... | |
#if (neko) Sys.sleep(1); #end | |
if (Random.bool()) | |
f.trigger(Success(new ContentResult('This is the result from a simulated async success! :-)'))); | |
else | |
f.trigger(Failure(new Error('This is a simulated async error - happens every second time...'))); | |
return f.asFuture(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment