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

finally() method from fcf.Actions class

fcf.Actions finally(function a_cb)

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Adds a callback to the run queue that is also called will be called on error

To determine if an error has occurred, you can use the fcf.Actions.error() method

When the handler is called, when an error occurs, the exceptions thrown from the handler are not processed and go outside.

Arguments

function a_cb
- A handler function that will be added to the task queue and will also be called if an error occurs. The result returned by the function will be passed to the next handler, but in case of error handling, if the function returns an object inherited from Error, then the current error in the fcf.Actions object is replaced.

A handler function can have two formats:

  • mixed a_cb(mixed a_lastResult) - Format without confirmation of completion of the operation. The function can be asynchronous. The execution of the next handler begins after the function has completed or the Promise or fcf.Actions object it returned has completed.

  • mixed a_cb(mixed a_lastResult, fcf.Actions.Act a_act) - Format with confirmation of completion of the operation. To complete an asynchronous operation, the handler function must call the fcf.Actions.Act.complete() method or fcf.Actions.Act.error() on an error. The result passed to the fcf.Actions.Act.complete() function call will be passed to the next handler.

Result
fcf.Actions
- Self pointer

Example: Function application

let actions = new fcf.Actions(); await actions .then(()=>{ /// doing something ... return "Hello world"; }) .finally(function(a_lastResult){ if(this.error()){ console.error("Error:", this.error().message); } else { console.log("Result:", a_lastResult); } });

Output:

Result: Hello world