Copyright | (c) Alejandro Durán Pallarés, 2016 |
---|---|
License | BSD3 |
Maintainer | vwwv@correo.ugr.es |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Data.JSVal.Promise
Description
Data.JSVal.Promise defines Promise
, a direct bind to javascript promise objects.
- You can import/export them from javascript code using its
FromJSVal
andToJSVal
instances. - You can extract its value, blocking till computation has finished, using
await
. (you can safely call it several time from different threads, the associated computation will run once, and then memorized) - You can create new promise (to possible use js side) containing arbitrary haskell code using
promise
.
For some usage example, checkout this blog entry.
Documentation
promise :: IO (Either JSVal JSVal) -> IO Promise Source #
A Right
value will be sent as a normal value through "then", a left
value will be sent through "catch" (by javascript convention, representing
an exception).
The block will start executing immediately, no mater if there's something waiting for it or not.
If the execution block launches an exception, then the promise will be receive as "reject", the javascript value "new Error('Haskell side error')"