Skip to content

Commit

Permalink
add async signaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Higginbotham committed Jul 17, 2024
1 parent 47f43e6 commit fcfa0d4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions content/docs/system/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,30 @@ responsible for forwarding all other signals to the subsystem.
should be imported into the subsystem. This is how the subsystems can reference
the parent system's component `[:services :stack]`.

## Async signaling

donut.system can send signals to components in parallel rather than one at a time.
To enable this, add `::ds/execute` to your system. The value should be a function
that executes a function asynchronously. For example:

``` clojure
(ds/start (assoc system ::ds/execute (fn [f] (future (f)))))
```

You might want to use an
[executor](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/Executor.html).
Here's how you could do that:

```clojure
(let [executor (java.util.concurrent.Executors/newFixedThreadPool 8)]
(try
(ds/start (assoc system ::ds/execute (fn [f] (.execute executor f)))
(finally
(.shutdown executor)))))
```

This is a Clojure-only feature. It's not implemented for ClojureScript.

## Purpose

Now that we've covered how to use the library, let's talk about why you'd use
Expand Down

0 comments on commit fcfa0d4

Please sign in to comment.