Scheduling tasks

137 views
Skip to first unread message

Nikolai Koudelia

unread,
Aug 1, 2016, 5:16:21 PM8/1/16
to Elm Discuss
Hi!

I need to schedule a task to be executed after a second but I can't really find a suitable function.

There is Time.now but I need Time.now + 1 second. There is also Time.every but I need the task to be triggered only once and only starting from some user action (e.g. clicking a button).

I guess I could use ports and subscribe for an action to be responded on the Javascript side using setTimeout()... but it just feels so awkward. Isn't there anything like "Time.after : Time -> Task x msg" existing?

BR
Nikolai

Max Goldstein

unread,
Aug 1, 2016, 5:28:41 PM8/1/16
to Elm Discuss
Process.sleep (1*Time.second)

Then use Task.andThen to perform your task.

Nikolai Koudelia

unread,
Aug 2, 2016, 4:25:19 PM8/2/16
to Elm Discuss
Yes, it works, thanks for the tip.

Didn't figure out to search for it under Process because I somehow expected that module to contain process-related stuff (which it does too - spawn, kill). Also "sleep" as a name for such a function doesn't feel right because traditionally sleep blocks current thread which Elm's Process.sleep doesn't do but returns a Task instead.
Reply all
Reply to author
Forward
0 new messages