Apify Discord Mirror

Updated 5 months ago

Javascript API SDK: How to call multiple actors simultaneously?

At a glance

The community member has a code that works to call a custom actor once, but they want to run multiple actors simultaneously. However, the current code doesn't work because each actor has to finish before the next one is initiated. The community members discuss a potential solution using the waitSecs option, which can be set to 0 if the number of calls is not too high, or to 2-3 seconds otherwise. One community member suggests trying the following code: for (let input of inputs) { const run = await client.actor("xyz").call(input, {waitSecs:3}); }

Useful resources
I have this code which works fine to call my custom actor a single time:
const run = await client.actor("xyz").call(input);

But I want to run multiple Actors simultaneously, like this:
Plain Text
for (let input of inputs) {
        const run = await client.actor("xyz").call(input);
    }


But obviously this doesn't work because each actor has to finish before the code initiates another actor. How do i do a synchronous call like this so I can trigger multiple actors? My data is all collected via webhook when the actor finishes, so I don't need wait for the run to finish in this codebase.
O
k
3 comments
You can set it to 0, if the number of calls is not that high (you can reach api call limits per sec).
Otherwise set 2-3 secs. Should be good.
Thanks! Would this work?

Plain Text
for (let input of inputs) {
        const run = await client.actor("xyz").call(input, {waitSecs:3});
    }
Add a reply
Sign up and join the conversation on Discord