Sha256: a97c438c976eecd8f9a4817465ceda1cba1eb0c0a33d76f953baabdd94011e64
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.maybeAsync = maybeAsync; exports.forwardAsync = forwardAsync; exports.isThenable = isThenable; exports.waitFor = exports.onFirstPause = exports.isAsync = void 0; const gensync = require("gensync"); const id = x => x; const runGenerator = gensync(function* (item) { return yield* item; }); const isAsync = gensync({ sync: () => false, errback: cb => cb(null, true) }); exports.isAsync = isAsync; function maybeAsync(fn, message) { return gensync({ sync(...args) { const result = fn.apply(this, args); if (isThenable(result)) throw new Error(message); return result; }, async(...args) { return Promise.resolve(fn.apply(this, args)); } }); } const withKind = gensync({ sync: cb => cb("sync"), async: cb => cb("async") }); function forwardAsync(action, cb) { const g = gensync(action); return withKind(kind => { const adapted = g[kind]; return cb(adapted); }); } const onFirstPause = gensync({ name: "onFirstPause", arity: 2, sync: function (item) { return runGenerator.sync(item); }, errback: function (item, firstPause, cb) { let completed = false; runGenerator.errback(item, (err, value) => { completed = true; cb(err, value); }); if (!completed) { firstPause(); } } }); exports.onFirstPause = onFirstPause; const waitFor = gensync({ sync: id, async: id }); exports.waitFor = waitFor; function isThenable(val) { return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function"; }
Version data entries
4 entries across 3 versions & 2 rubygems