wrapAsync.js 955 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isAsyncIterable = exports.isAsyncGenerator = exports.isAsync = undefined;
  6. var _asyncify = require('../asyncify.js');
  7. var _asyncify2 = _interopRequireDefault(_asyncify);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function isAsync(fn) {
  10. return fn[Symbol.toStringTag] === 'AsyncFunction';
  11. }
  12. function isAsyncGenerator(fn) {
  13. return fn[Symbol.toStringTag] === 'AsyncGenerator';
  14. }
  15. function isAsyncIterable(obj) {
  16. return typeof obj[Symbol.asyncIterator] === 'function';
  17. }
  18. function wrapAsync(asyncFn) {
  19. if (typeof asyncFn !== 'function') throw new Error('expected a function');
  20. return isAsync(asyncFn) ? (0, _asyncify2.default)(asyncFn) : asyncFn;
  21. }
  22. exports.default = wrapAsync;
  23. exports.isAsync = isAsync;
  24. exports.isAsyncGenerator = isAsyncGenerator;
  25. exports.isAsyncIterable = isAsyncIterable;