Telling Elm to wait

Hello,

I am having a hard time trying to find a sleep(seconds) function similar to setTimeout(ms, callback) in JS or time.sleep(ms) in Python. So far, the most similar workaround I’ve found is to use the http module, that allows for a timeout when doing requests.
Does actually something like this exist in Elm? Can this be adapted to the way the Elm architecture works?

Thanks in advance! :blush:

PS: I’m willing to do a port of the typed.js module in Elm, however I don’t get the clue of how to update one letter at a time + making Elm to wait to simulate the animation)

You’re looking for the Process.sleep function from elm/core.

This function will give you back a Task that you can combo with other tasks or convert to a command with Task.perform. Your update function will get the given message when the sleep completes.

Here’s an executable example showing a sleep in action.

5 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.