Documentation v4.0.0

Overview

Check if a value is an asynchronous function.

Import

import {utils} from 'metronic-extension';
const {isAsyncFn} = utils;

Signature

isAsyncFn(payload: any): boolean
Parameter Type Description
payload any The value to test.
Returns: booleantrue for asynchronous functions, false otherwise.

Example

ValueResult
<table class="table table-row-bordered" id="isAsyncFnDemo">
  <thead><tr class="fw-bold fs-6 text-gray-800"><th>Value</th><th>Result</th></tr></thead>
  <tbody></tbody>
</table>
var isAsyncFn = metronicExtension.utils.isAsyncFn;
var testCases = [
  {label: "async function(){}", value: async function(){}},
  {label: "function(){}", value: function(){}},
  {label: "42", value: 42},
  {label: "'string'", value: 'string'},
  {label: "true", value: true},
  {label: "null", value: null},
  {label: "{}", value: {}},
  {label: "[]", value: []},
];
var tbody = document.querySelector('#isAsyncFnDemo tbody');
testCases.forEach(function(tc) {
  var valid = isAsyncFn(tc.value);
  var tr = document.createElement('tr');
  tr.innerHTML = '<td><code>' + tc.label + '</code></td>'
    + '<td><span class="badge ' + (valid ? 'badge-success' : 'badge-danger')
    + '">' + valid + '</span></td>';
  tbody.appendChild(tr);
});