@@ -7,11 +7,14 @@ module GHCJS.Foreign.Callback
77 , asyncCallback
88 , asyncCallback1
99 , asyncCallback2
10+ , asyncCallback3
1011 , syncCallback
1112 , syncCallback1
1213 , syncCallback2
14+ , syncCallback3
1315 ) where
1416
17+ import GHCJS.Concurrent
1518import GHCJS.Marshal
1619import GHCJS.Marshal.Pure
1720import GHCJS.Foreign.Callback.Internal
@@ -24,17 +27,6 @@ import Data.Typeable
2427
2528import Unsafe.Coerce
2629
27- {- |
28- The runtime tries to run synchronous threads to completion. Sometimes it's
29- not possible to continue running a thread, for example when the thread
30- tries to take an empty 'MVar'. The runtime can then either throw a
31- 'WouldBlockException', aborting the blocking action, or continue the
32- thread asynchronously.
33- -}
34- data OnBlocked = ContinueAsync -- ^ continue the thread asynchronously if blocked
35- | ThrowWouldBlock -- ^ throw 'WouldBlockException' if blocked
36- deriving (Show , Eq , Enum , Typeable )
37-
3830{- |
3931 When you create a callback, the Haskell runtime stores a reference to
4032 the exported IO action or function. This means that all data referenced by the
@@ -84,6 +76,19 @@ syncCallback2 :: OnBlocked -- ^ what to do when th
8476 -> IO (Callback (JSVal -> JSVal -> IO () )) -- ^ the callback
8577syncCallback2 onBlocked x = js_syncCallbackApply (onBlocked == ContinueAsync ) 2 (unsafeCoerce x)
8678
79+ {- | Make a callback (JavaScript function) that runs the supplied IO function in a synchronous
80+ thread when called. The callback takes three arguments that it passes as JSVal values to
81+ the Haskell function.
82+
83+ Call 'releaseCallback' when done with the callback, freeing data referenced
84+ by the function.
85+ -}
86+ syncCallback3 :: OnBlocked -- ^ what to do when the thread blocks
87+ -> (JSVal -> JSVal -> JSVal -> IO () ) -- ^ the Haskell function
88+ -> IO (Callback (JSVal -> JSVal -> JSVal -> IO () )) -- ^ the callback
89+ syncCallback3 onBlocked x = js_syncCallbackApply (onBlocked == ContinueAsync ) 3 (unsafeCoerce x)
90+
91+
8792
8893{- | Make a callback (JavaScript function) that runs the supplied IO action in an asynchronous
8994 thread when called.
@@ -103,6 +108,10 @@ asyncCallback2 :: (JSVal -> JSVal -> IO ()) -- ^ the Haskell function
103108 -> IO (Callback (JSVal -> JSVal -> IO () )) -- ^ the callback
104109asyncCallback2 x = js_asyncCallbackApply 2 (unsafeCoerce x)
105110
111+ asyncCallback3 :: (JSVal -> JSVal -> JSVal -> IO () ) -- ^ the Haskell function that the callback calls
112+ -> IO (Callback (JSVal -> JSVal -> JSVal -> IO () )) -- ^ the callback
113+ asyncCallback3 x = js_asyncCallbackApply 3 (unsafeCoerce x)
114+
106115-- ----------------------------------------------------------------------------
107116
108117foreign import javascript unsafe " h$makeCallback(h$runSync, [$1], $2)"
0 commit comments