Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFI Requires setTimeout #176

Open
BebeSparkelSparkel opened this issue Aug 1, 2019 · 4 comments
Open

FFI Requires setTimeout #176

BebeSparkelSparkel opened this issue Aug 1, 2019 · 4 comments

Comments

@BebeSparkelSparkel
Copy link

BebeSparkelSparkel commented Aug 1, 2019

When using FFI for Aff I need to use setTimeout before calling onSuccess or else the page hangs as if onSuccess was never called. Feels like there is some listener setup in the wrong order or onSuccess is defined after the return.

Failing example without timeout.

exports.failing = s => (onError, onSuccess) => {
  onSuccess(s)
  return (cancelError, cancelerError, cancelerSuccess) => {cancelerSuccess()}
}

Working example with timeout.

exports.working = s => (onError, onSuccess) => {
  setTimeout(() => onSuccess(s), 100)
  return (cancelError, cancelerError, cancelerSuccess) => {cancelerSuccess()}
}
@natefaubion
Copy link
Collaborator

natefaubion commented Aug 2, 2019

I cannot reproduce this with a modified version of the EffectFn test that always resolves immediately. I suspect that you have some sort of race condition in your code. Could you post a self contained example?

@BebeSparkelSparkel
Copy link
Author

Created an example

https://github.com/BebeSparkelSparkel/aff-error

@natefaubion
Copy link
Collaborator

This is because you are typing it as Aff. Aff's representation is opaque. You need to type it as EffectFnAff and use the Compat module.

-- | foreign import _myAff :: EffectFnAff String
-- |
-- | myAff :: Aff String
-- | myAff = fromEffectFnAff _myAff

@BebeSparkelSparkel
Copy link
Author

Sorry about that. Just fixed it and am still having the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants