@@ -168,15 +168,15 @@ This is where it gets interesting. You can trigger a task and then wait for the
168
168
<Accordion title = " Don't use this in parallel, e.g. with `Promise.all()`" >
169
169
Instead, use ` batchTriggerAndWait() ` if you can, or a for loop if you can't.
170
170
171
+ To control concurrency using batch triggers, you can set ` queue.concurrencyLimit ` on the child task.
172
+
171
173
<CodeGroup >
172
174
``` ts /trigger/batch.ts
173
175
export const batchTask = task ({
174
176
id: " batch-task" ,
175
177
run : async (payload : string ) => {
176
178
const results = await childTask .batchTriggerAndWait ({
177
179
items: [{ payload: " item1" }, { payload: " item2" }],
178
- // optional: how many to run in parallel
179
- batchOptions: { maxConcurrency: 1 },
180
180
});
181
181
console .log (" Results" , results );
182
182
@@ -189,6 +189,8 @@ export const batchTask = task({
189
189
export const loopTask = task ({
190
190
id: " loop-task" ,
191
191
run : async (payload : string ) => {
192
+ // this will be slower than the batch version
193
+ // as we have to resume the parent after each iteration
192
194
for (let i = 0 ; i < 2 ; i ++ ) {
193
195
const result = await childTask .triggerAndWait ({ payload: ` item${i } ` });
194
196
console .log (" Result" , result );
@@ -221,15 +223,15 @@ You can batch trigger a task and wait for all the results. This is useful for th
221
223
<Accordion title = " Don't use this in parallel, e.g. with `Promise.all()`" >
222
224
Instead, pass in all items at once and set an appropriate ` maxConcurrency ` . Alternatively, use sequentially with a for loop.
223
225
226
+ To control concurrency, you can set ` queue.concurrencyLimit ` on the child task.
227
+
224
228
<CodeGroup >
225
229
``` ts /trigger/batch.ts
226
230
export const batchTask = task ({
227
231
id: " batch-task" ,
228
232
run : async (payload : string ) => {
229
233
const results = await childTask .batchTriggerAndWait ({
230
234
items: [{ payload: " item1" }, { payload: " item2" }],
231
- // optional: how many tasks to run in parallel
232
- batchOptions: { maxConcurrency: 1 },
233
235
});
234
236
console .log (" Results" , results );
235
237
@@ -242,11 +244,11 @@ export const batchTask = task({
242
244
export const loopTask = task ({
243
245
id: " loop-task" ,
244
246
run : async (payload : string ) => {
247
+ // this will be slower than a single batchTriggerAndWait()
248
+ // as we have to resume the parent after each iteration
245
249
for (let i = 0 ; i < 2 ; i ++ ) {
246
250
const result = await childTask .batchTriggerAndWait ({
247
251
items: [{ payload: ` itemA${i } ` }, { payload: ` itemB${i } ` }],
248
- // optional: how many tasks to run in parallel
249
- batchOptions: { maxConcurrency: 1 },
250
252
});
251
253
console .log (" Result" , result );
252
254
0 commit comments