Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Dec 4, 2023
1 parent a7a2666 commit 99a7253
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions doc/executors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ for asynchronous execution.
Although this API works in the JS runtime and some of the function has
general utility, the main target is the JVM platform.


## Async Tasks

Firstly, lets define **async task**: a function that is executed out
of current flow using a different thread. Here, **promesa** library
exposes mainly two functions:

- `promesa.exec/run!`: useful when you want run a function in a
- `promesa.exec/run`: useful when you want run a function in a
different thread and you don't care abour the return value; it
returns a promise that will be fullfilled when the callback
terminates.
- `promesa.exec/submit!` useful when you want run a function in a
- `promesa.exec/submit` useful when you want run a function in a
different thread and you need the return value; it returns a promise
that will be fullfilled with the return value of the function.

Expand All @@ -30,14 +31,14 @@ Let see some examples:
(require '[promesa.exec :as px])


@(px/run! (fn []
(prn "I'm running in different thread")
1))
@(px/run (fn []
(prn "I'm running in different thread")
1))
;; => nil

@(px/submit! (fn []
(prn "I'm running in different thread")
1))
@(px/submit (fn []
(prn "I'm running in different thread")
1))
;; => 1
```

Expand All @@ -60,8 +61,8 @@ function after some amount of time.

```clojure
(require '[promesa.exec :as exec])
(exec/schedule! 1000 (fn []
(println "hello world")))
(exec/schedule 1000 (fn []
(println "hello world")))
```

This example shows you how you can schedule a function call to be
Expand All @@ -71,7 +72,7 @@ Clojure and ClojureScript.
The tasks can be cancelled using its return value:

```clojure
(def task (exec/schedule! 1000 #(do-stuff)))
(def task (exec/schedule 1000 #(do-stuff)))

(p/cancel! task)
```
Expand Down

0 comments on commit 99a7253

Please sign in to comment.