Node.js util.types.isAsyncFunction() Method
The util.types.isAsyncFunction() method is an inbuilt application programming interface of the util module which is used to type check for asynchronous functions in the node.js.
Syntax:
util.types.isAsyncFunction( value )
Parameters: This method accepts a single parameter as mentioned above and described below:
- value: It is a required parameter that holds any data type.
Return Value: It returns a boolean value, TRUE if the value is an async function from the perspective of the JavaScript engine, FALSE otherwise.
The below examples illustrate the use of util.types.isAsyncFunction() method in Node.js:
Example 1:
javascript
// Node.js program to demonstrate the // util.types.isAsyncFunction() Method // Allocating util module const util = require( 'util' ); // Functions to be passed as parameter of // util.types.isAsyncFunction() method let f2 = async function function2() { } let f1 = function function1() { } // Printing the returned value from // util.types.isAsyncFunction() method console.log(util.types.isAsyncFunction(f2)); console.log(util.types.isAsyncFunction(f1)); |
Output:
true false
Example 2:
javascript
// Node.js program to demonstrate the // util.types.isAsyncFunction() Method // Allocating util module const util = require( 'util' ); // Functions to be passed as parameter const f2 = async function function2() { } const f1 = function function1() { } // Calling util.types.isAsyncFunction() method if (util.types.isAsyncFunction(f2)) console.log( "The passed value is an Async function." ); else console.log( "The passed value is not an Async function" ); if (util.types.isAsyncFunction(f1)) console.log( "The passed value is an Async function." ); else console.log( "The passed value is not an Async function" ); |
Output:
The passed value is an Async function. The passed value is not an Async function
Note: The above program will compile and run by using the node filename.js command.
Reference: https://nodejs.org/api/util.html#util_util_types_isasyncfunction_value
Please Login to comment...