Class: fcf.ActionsQueue
Package: fcf-framework-core
File: fcf.js
Available from version: 2.0.16
The getAsyncActions method allows grouping asynchronous tasks into named streams within a queue. It provides synchronization: the execution of the entire queue will be suspended until all tasks in the specified group have completed. The getAsyncActions method allows grouping asynchronous tasks into named streams within a queue. It provides synchronization: the execution of the entire queue will be suspended until all tasks in the specified group have completed.
The getAsyncActions method is designed to manage parallel and sequential streams of asynchronous operations within a single fcf.ActionsQueue.
How it works:
-
Task Grouping: When the method is called with a group name (a_group), tasks are combined into a logical block.
-
Stream Synchronization: If tasks from another group are already executing in the queue, the new group will wait for their completion. If the method is called for an existing group, new tasks are appended to it.
-
Append Mode (a_appendMode):
- If a_appendMode is true, new tasks are added to the existing group with the same name.
- If a_appendMode is false, a new independent group is created.
Result
fcf.Actions
- The method returns an fcf.Actions object that will transition to a completed state only after all tasks in that group have finished.
Detailed description
Exceptions:
The method itself does not throw exceptions; however, the returned fcf.Actions object may contain errors encountered during the execution of tasks within the group. To handle these errors, use the catch method.
Example: Parallel task execution in a group
let fcf = require("fcf-framework-core");
let queue = new fcf.ActionsQueue();
// Adding tasks to the "upload" group
for(let i = 0; i < 3; i++) {
(function(i){
queue.getAsyncActions("upload").then(() => {
return fcf.actions()
.then(()=>{
fcf.log.log("App", "upload '" + i + "' started");
})
.wait(1000)
.then(()=>{
fcf.log.log("App", "upload '" + i + "' completed");
});
});
})(i);
}
// Adding tasks to the "processing" group
for(let i = 0; i < 3; i++) {
(function(i){
queue.getAsyncActions("upload").then(() => {
return fcf.actions()
.then(()=>{
fcf.log.log("App", "processing '" + i + "' started");
})
.wait(1000)
.then(()=>{
fcf.log.log("App", "processing '" + i + "' completed");
});
});
})(i);
}
// Adding tasks to the "upload" group
for(let i = 0; i < 3; i++) {
(function(i){
queue.getAsyncActions("upload").then(() => {
return fcf.actions()
.then(()=>{
fcf.log.log("App", "upload '" + i + "' started");
})
.wait(1000)
.then(()=>{
fcf.log.log("App", "upload '" + i + "' completed");
});
});
})(i);
}
// This block will execute only after all tasks
queue.getActions().then(() => {
fcf.log.log("App", "All uploads completed");
});
Output:
2026-05-24 01:21:13.397 [PID:18832] [LOG] [MOD:App]: upload '0' started
2026-05-24 01:21:13.404 [PID:18832] [LOG] [MOD:App]: upload '1' started
2026-05-24 01:21:13.404 [PID:18832] [LOG] [MOD:App]: upload '2' started
2026-05-24 01:21:14.404 [PID:18832] [LOG] [MOD:App]: upload '0' completed
2026-05-24 01:21:14.405 [PID:18832] [LOG] [MOD:App]: upload '1' completed
2026-05-24 01:21:14.406 [PID:18832] [LOG] [MOD:App]: upload '2' completed
2026-05-24 01:21:14.407 [PID:18832] [LOG] [MOD:App]: processing '0' started
2026-05-24 01:21:14.407 [PID:18832] [LOG] [MOD:App]: processing '1' started
2026-05-24 01:21:14.407 [PID:18832] [LOG] [MOD:App]: processing '2' started
2026-05-24 01:21:15.409 [PID:18832] [LOG] [MOD:App]: processing '0' completed
2026-05-24 01:21:15.410 [PID:18832] [LOG] [MOD:App]: processing '1' completed
2026-05-24 01:21:15.410 [PID:18832] [LOG] [MOD:App]: processing '2' completed
2026-05-24 01:21:15.411 [PID:18832] [LOG] [MOD:App]: upload '0' started
2026-05-24 01:21:15.411 [PID:18832] [LOG] [MOD:App]: upload '1' started
2026-05-24 01:21:15.412 [PID:18832] [LOG] [MOD:App]: upload '2' started
2026-05-24 01:21:16.413 [PID:18832] [LOG] [MOD:App]: upload '0' completed
2026-05-24 01:21:16.413 [PID:18832] [LOG] [MOD:App]: upload '1' completed
2026-05-24 01:21:16.414 [PID:18832] [LOG] [MOD:App]: upload '2' completed
2026-05-24 01:21:16.415 [PID:18832] [LOG] [MOD:App]: All uploads completed
Example: Appending to an existing group
let fcf = require("fcf-framework-core");
let queue = new fcf.ActionsQueue();
// Create a group batch1
queue.getAsyncActions("batch1")
.then(()=>{
fcf.log.log("App", "task1 (batch1) started");
})
.wait(1000)
.then(()=>{
fcf.log.log("App", "task1 (batch1) completed");
})
// Create a new group batch2
queue.getAsyncActions("batch2")
.then(()=>{
fcf.log.log("App", "task 2 (batch2) started");
})
.wait(1000)
.then(()=>{
fcf.log.log("App", "task 2 (batch2) completed");
})
// Add to the same group (a_appendMode = true)
// This method with the flag appendMode will add to the last
// existing group with this name or create a new one.
// Regardless of the fact that there is already a batch2 group in turn.
queue.getAsyncActions("batch1", true)
.then(()=>{
fcf.log.log("App", "task3 (batch1) started");
})
.wait(1000)
.then(()=>{
fcf.log.log("App", "task3 (batch1) completed");
})
// Wait for the entire "batch" groups to finish
queue.getActions().then(() => {
fcf.log.log("App", "Batch group fully processed");
});
Output:
2026-05-24 01:16:27.471 [PID:18389] [LOG] [MOD:App]: task1 (batch1) started
2026-05-24 01:16:27.471 [PID:18389] [LOG] [MOD:App]: task3 (batch1) started
2026-05-24 01:16:28.473 [PID:18389] [LOG] [MOD:App]: task1 (batch1) completed
2026-05-24 01:16:28.473 [PID:18389] [LOG] [MOD:App]: task3 (batch1) completed
2026-05-24 01:16:28.474 [PID:18389] [LOG] [MOD:App]: task 2 (batch2) started
2026-05-24 01:16:29.476 [PID:18389] [LOG] [MOD:App]: task 2 (batch2) completed
2026-05-24 01:16:29.477 [PID:18389] [LOG] [MOD:App]: Batch group fully processed