# Delay ⌚
A dead simple data-structure for delaying side effects ⌚! Written in the excellent [gleam ✨](https://gleam.run/) language. Supporting both Erlang & Javascript targets
[](https://github.com/bwireman/delay/actions/workflows/test.yml)
[](https://github.com/bwireman/delay/commit/main)
[](https://github.com/bwireman/delay/blob/main/LICENSE)
[](http://makeapullrequest.com)
[](https://hexdocs.pm/delay/index.html)
[](https://gleam.run)
[](https://hex.pm/packages/delay/)
[](https://gleam.run/news/v0.16-gleam-compiles-to-javascript/)
## Basic Usage
```gleam
import gleam/io
import delay
let d = delay.delay_effect(fn() {
io.println("Hello")
Ok(1)
}) |> delay.map(fn(x) {
io.println("World")
Ok(x + 1)
})
let res = delay.run(d)
// Hello
// World
// res = Ok(2)
```
## More info
The result of `delay_effect` is really just a first class function with a nice API wrapper. It isn't executed until put through one of `run/1`, `drain/1`, `fallthrough/1` or one of the other functions in order to execute a delayed effect. And can be called as many times as you want.
```gleam
import gleam/io
import delay
let d = delay.delay_effect(fn() {
io.println("Hello")
Error("bummer")
}) |> delay.map(fn(x) {
io.println("World")
Ok(x + 1)
})
let res = delay.run(d)
// Hello
// res = Error("bummer")
```
If one of the functions in the chain fails, the rest will short circuit and the error will be returned.
Effects can be retried as well via `retry/3`
```gleam
// using the same effect `d` from above
let res = delay.retry(d, 3, 200)
|> delay.run()
// Hello
// Hello
// Hello
// Hello
// res = Error("bummer")
```
## FAQ
Doesn't the concept of a delayed side effect kind of lose value in the world of actor model concurrency and zero shared memory?!
> A little
Then why did you write this?
> For fun
Is gleam ✨ actually excellent?
> So far