The simplest way is to define your own foreign import for setTimeout
:
module SetTimeout where
foreign import data TIMEOUT :: !
foreign import timeout :: forall eff a.
Int ->
Eff (timeout :: TIMEOUT | eff) a ->
Eff (timeout :: TIMEOUT | eff) Unit
In your foreign Javascript module, you can define setTimeout
as follows:
"use strict";
// module SetTimeout
exports.timeout = function(millis) {
return function(action) {
return function() {
setTimeout(action, millis);
};
};
};
You would be able to extend this to work with things like clearTimeout
if needed.
Some other possible approaches: