Previous: Managing Task Concurrency
Next: Cancelation
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.
export default class SharedTasksAdvancedController extends Controller { @task({ maxConcurrency: 3, restartable: true }) restartableTask3 = SHARED_TASK_FN; @task({ maxConcurrency: 3, enqueue: true }) enqueuedTask3 = SHARED_TASK_FN; @task({ maxConcurrency: 3, drop: true }) droppingTask3 = SHARED_TASK_FN; @task({ maxConcurrency: 3, keepLatest: true }) keepLatestTask3 = SHARED_TASK_FN; }
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.
maxConcurrency: 3
maxConcurrency: 3
maxConcurrency: 3
Thanks to Edward Faulkner for providing a starting point for the graphs :)
Previous: Managing Task Concurrency
Next: Cancelation