A drop in replacement for elm/core's Process.sleep.
The JavaScript runner has this task builtin by default. If needed it can be overridden like so:
NOTE: The custom example is the same as the built-in implementation.
import * as ConcurrentTask from "@andrewmacmurray/elm-concurrent-task"
ConcurrentTask.register({
tasks: {},
ports: app.ports,
builtins: {
sleep: customSleep
}
});
function customSleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}Cancel a task, succeeding with the given value if the task takes longer than the given milliseconds.
import ConcurrentTask exposing (ConcurrentTask)
import ConcurrentTask.Http as Http
import ConcurrentTask.Process
type Fruits
= Cached (List String)
| Loaded (List String)
loadFruits : ConcurrentTask Http.Error Fruits
loadFruits =
getFruits
|> ConcurrentTask.withTimeout 2000 (Cached [ "Apple", "Orange", "Banana" ])If getFruits takes longer than 2000ms the task will succeed with the Cached value.
Wait for a number of milliseconds before continuing with the next Task.
A direct replacement for
elm/core'sProcess.sleep.