UNPKG

is-awaitable

Version:

A lightweight solution for detecting async functions.

2 lines (1 loc) 353 B
"use strict";const t=Object.getPrototypeOf((async()=>{})).constructor,n=Object.getPrototypeOf((async function*(){})).constructor;exports.isAwaitable=function(o){if("function"!=typeof o)return!1;if(o instanceof t||o instanceof n)return!0;const c=Function.prototype.toString.call(o).trim();return c.startsWith("async ")||c.startsWith("async function*")};