isAsyncFunction.js 598 B

12345678910111213141516171819202122
  1. 'use strict';
  2. let asyncFunctionPrototype = null;
  3. // try/catch for Babel compatibility, because Babel preset-env requires
  4. // regenerator-runtime for async/await and we don't want to include that
  5. // for a simple check.
  6. try {
  7. asyncFunctionPrototype = Object.getPrototypeOf(async function() {});
  8. } catch (err) {}
  9. if (asyncFunctionPrototype == null) {
  10. module.exports = function isAsyncFunction() {
  11. return false;
  12. };
  13. } else {
  14. module.exports = function isAsyncFunction(v) {
  15. return (
  16. typeof v === 'function' &&
  17. Object.getPrototypeOf(v) === asyncFunctionPrototype
  18. );
  19. };
  20. }