Created
July 19, 2015 17:30
-
-
Save joshcough/6ac517c6b972f004816a to your computer and use it in GitHub Desktop.
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
def asyncTask(i: I)(implicit e: Executor): Task[O] = Task.suspend({ | |
Task.async { (cb: (Throwable \/ O) => Unit) => | |
Futures.addCallback(eval(i), new FutureCallback[O]() { | |
def onSuccess(result: O) = { | |
cb(result.right) | |
self.onSuccess(result) | |
} | |
def onFailure(t: Throwable) = { | |
cb(t.left) | |
self.onFailure(t) | |
} | |
}, e) | |
} | |
}) | |
def syncTask(i: I)(implicit e: Executor): Task[O] = Task.suspend({ | |
val fo = eval(i) | |
Futures.addCallback(fo, new FutureCallback[O]() { | |
def onSuccess(result: O) = self.onSuccess(result) | |
def onFailure(t: Throwable) = self.onFailure(t) | |
}, e) | |
Task(fo.get) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment