Using maxConcurrency: N

The examples on the previous page limit the concurrency of a task to 1 — only one instance of a task can run at a time. Most of the time, this is exactly what you want.

There are some cases, however, when you might want to limit the number of concurrently running task instances to a number greater than 1. In such cases, you can use the task modifier maxConcurrency: n to opt into a specific maximum concurrency other than 1.

The examples below use the same task modifiers as the ones on the previous page, but with maxConcurrency: 3 applied to them: they each allow 3 running instances before enqueuing, canceling, or dropping perform()s.

restartable with maxConcurrency: 3

When concurrency exceeds maxConcurrency, the oldest running task is canceled.

TODO: while restartable is an excellent name when maxConcurrency is 1, it poorly describes the behavior for values greater than 1. A better name in this case might be "sliding", as in sliding buffer.

enqueue with maxConcurrency: 3

drop with maxConcurrency: 3

keepLatest with maxConcurrency: 3

Thanks to Edward Faulkner for providing a starting point for the graphs :)