FCF 2.0 development in progress...
> > > > > >
[News] [JS Packages API] [JS Downloads] [Donate to the project] [Contacts]

getActions() method from fcf.ActionsQueue class

fcf.Actions getActions()

Class: fcf.ActionsQueue

Package: fcf-framework-core

File: fcf.js

Available from version: 2.0.16

The getActions method returns an fcf.Actions object that manages the current task queue. It ensures sequential execution of tasks by chaining new actions to the completion of all previously scheduled operations in the queue and automatically triggers the execution of accumulated completion callbacks.

The getActions() method is a key tool for managing the flow of asynchronous operations within a single fcf.ActionsQueue. Its primary purpose is to provide an interface for adding new tasks to a chain, guaranteeing their strict sequence relative to existing tasks.

How it works:
  • Chain Linking: If there is an active task in the queue, the new fcf.Actions object returned by the method is automatically attached to the completion (finally) of the previous task. This allows for building long, sequential chains of asynchronous calls.
  • Completion Management: The method checks for accumulated callbacks that were scheduled to run immediately upon the conclusion of previous operations. If such callbacks exist, they are executed before control is passed to the new chain.
  • Initialization: If the queue is empty, the method creates a new, independent action chain.
Exceptions:

The method itself does not throw exceptions; however, the returned fcf.Actions object may contain errors encountered during the execution of tasks in the queue. To handle these errors, use the catch() method on the returned object.

Result
fcf.Actions
- The returned fcf.Actions object acts as a specialized asynchronous controller for the task currently being added to the queue. It provides the following capabilitiesThe returned fcf.Actions object acts as a specialized asynchronous controller for the task currently being added to the queue.

Example: Sequential Task Execution

let fcf = require("fcf-framework-core"); let queue = new fcf.ActionsQueue(); // First task queue.getActions().then(() => { fcf.log.log("APP", "Task 1 completed"); }); // Second task (will automatically wait for the first task to finish) queue.getActions().then(() => { fcf.log.log("APP", "Task 2 completed"); });

Output:

2026-05-23 02:20:27.627 [PID:424945] [LOG] [MOD:APP]: Task 1 completed 2026-05-23 02:20:27.634 [PID:424945] [LOG] [MOD:APP]: Task 2 completed

Example: Using with Asynchronous Operations

let fcf = require("fcf-framework-core"); async function main() { let queue = new fcf.ActionsQueue(); async function asyncTask(id) { fcf.log.log("APP", "Async task " + id + " start"); await new Promise(resolve => setTimeout(resolve, 1000)); fcf.log.log("APP", "Async task " + id + " done"); } // Adding tasks to the queue queue.getActions().then(() => asyncTask(1)); queue.getActions().then(() => asyncTask(2)); // Waiting for the entire queue to finish await queue.getActions().then(() => { fcf.log.log("APP", "Entire queue processed"); }); } main();

Output:

2026-05-23 02:44:12.387 [PID:425851] [LOG] [MOD:APP]: Async task 1 start 2026-05-23 02:44:13.390 [PID:425851] [LOG] [MOD:APP]: Async task 1 done 2026-05-23 02:44:13.390 [PID:425851] [LOG] [MOD:APP]: Async task 2 start 2026-05-23 02:44:14.393 [PID:425851] [LOG] [MOD:APP]: Async task 2 done 2026-05-23 02:44:14.393 [PID:425851] [LOG] [MOD:APP]: Entire queue processed