Skip to content

Instantly share code, notes, and snippets.

@cambiata
Created December 18, 2014 12:35
Show Gist options
  • Save cambiata/c40e097f1e4d98c130e2 to your computer and use it in GitHub Desktop.
Save cambiata/c40e097f1e4d98c130e2 to your computer and use it in GitHub Desktop.
Example use of tink.core.Future in UFront controllers
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