is-awaitable
Version:
A lightweight solution for detecting async functions.
2 lines (1 loc) • 580 B
JavaScript
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).IsAwaitable={})}(this,(function(t){"use strict";const n=Object.getPrototypeOf((async()=>{})).constructor,e=Object.getPrototypeOf((async function*(){})).constructor;t.isAwaitable=function(t){if("function"!=typeof t)return!1;if(t instanceof n||t instanceof e)return!0;const o=Function.prototype.toString.call(t).trim();return o.startsWith("async ")||o.startsWith("async function*")}}));