Closed crocket closed 7 years ago
LGTM
@hamishmack Would it be ok to replace JavaScript.Array.toListIO :: SomeJSArray m -> IO [JSVal]
with GHCJS.Prim.fromJSArray :: JSVal -> IO [JSVal]
in my multi-argument callback functions? I presented the definition of syncCallbackMulti
below to facilitate discussion.
{- | Make a callback (JavaScript function) that runs the supplied IO function
in a synchronous thread when called. The callback takes an arbitrary
number of arguments that it passes as an array of JSVal values to the
Haskell function.
Call 'releaseCallback' on the callback when done with the callback,
freeing data referenced by the function.
-}
syncCallbackMulti :: OnBlocked -- ^ what to do when the thread blocks
-> ([JSVal] -> IO ()) -- ^ the Haskell action
-> IO (Callback ([JSVal] -> IO ())) -- ^ the callback
syncCallbackMulti onBlocked f = do
js_syncCallbackMulti (onBlocked == ContinueAsync) $ unsafeCoerce $ \args ->
Array.toListIO (unsafeCoerce args) >>= f
Update 1. the above function is now gone. The functions are now replaced with polyvariadic variants.
I think it would be fine.
@hamishmack @luite I think the pull request is ready for merge. I request that a tag, v0.2.1.0
be added to the git repository after merging this pull request. Is it ok for you to do so?
This pull request does several things.
h$makeCallbackMulti
.GHCJS/Foreign/Callback/Variadic.hs
which enables polyvariadic callback functions.syncCallbackMulti
,syncCallbackMulti'
, andasyncCallbackMulti
to GHCJS/Foreign/Callback.hs. These functions utilizeh$makeCallbackMulti
andVariadicCallback
for convenience of users. Refer to README for details.OnBlocked
andsyncCallback'
more clearly on README.syncCallbackMulti
,syncCallbackMulti'
, andasyncCallbackMulti
on README.I tested
syncCallbackMulti
,syncCallbackMulti'
, andasyncCallbackMulti
against the NodeJS example I included in README, and the functions worked well in my example.This closes https://github.com/ghcjs/ghcjs-base/issues/76
It doesn't break existing functions. Thus, I want this pull request to be merged as soon as possible if maintainers don't have major objections.