I'm a total PureScript newbie and need a bit of help figuring out why a FFI function modeled with the Aff monad doesn't seem to be working for me.
The expected behavior is to log a message "keyMessage" to the console after 1000ms.
Instead, the program just hangs indefinitely after the following output:
Compiling Main
* Build successful.
Waiting for message...
Main.purs:
module Main where
import Prelude
import Control.Monad.Aff (Aff, Fiber, launchAff)
import Control.Monad.Aff.Console (log)
import Control.Monad.Eff (Eff, kind Effect)
import Control.Monad.Eff.Console (CONSOLE)
main :: forall e. Eff (console :: CONSOLE, to :: TIMEOUT | e) (Fiber (console :: CONSOLE, to :: TIMEOUT | e) Unit)
main = launchAff do
log "Waiting for message..."
m <- message "key"
log m
foreign import data TIMEOUT :: Effect
foreign import message :: forall e. String -> Aff (to :: TIMEOUT | e) String
Main.js:
'use strict';
exports.message = function(key) {
return function(errback, callback) {
var timeout = setTimeout(function() {
callback(key + 'Message');
}, 1000);
return function() {
return function (cancelErrback, cancelCallback) {
clearTimeout(timeout);
return cancelCallback();
};
};
};
};
Thanks in advance for your insights!
makeAffand useEffin your foreign function imports. - Felix Schlitter