Skip to content

Instantly share code, notes, and snippets.

@pravdomil
Created April 9, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pravdomil/9022e68fdd8aa1abf8f5fcd64476839d to your computer and use it in GitHub Desktop.
Save pravdomil/9022e68fdd8aa1abf8f5fcd64476839d to your computer and use it in GitHub Desktop.
Use micro task queue.
/*
import Elm.Kernel.Scheduler exposing (binding, succeed)
import Elm.Kernel.Utils exposing (Tuple0)
*/
function _Process_sleep(time)
{
return __Scheduler_binding(function(callback) {
if (time === 0) {
var canceled = false;
Promise.resolve().then(function() {
if (!canceled) {
callback(_Scheduler_succeed(_Utils_Tuple0));
}
})
return function() {
canceled = true;
}
}
var id = setTimeout(function() {
callback(__Scheduler_succeed(__Utils_Tuple0));
}, time);
return function() { clearTimeout(id); };
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment