UNPKG

@segment/analytics-core

Version:

This package represents core 'shared' functionality that is shared by analytics packages. This is not designed to be used directly, but internal to analytics-node and analytics-browser.

20 lines 714 B
import { isThenable } from '../utils/is-thenable'; export var createTaskGroup = function () { var taskCompletionPromise; var resolvePromise; var count = 0; return { done: function () { return taskCompletionPromise; }, run: function (op) { var returnValue = op(); if (isThenable(returnValue)) { if (++count === 1) { taskCompletionPromise = new Promise(function (res) { return (resolvePromise = res); }); } returnValue.finally(function () { return --count === 0 && resolvePromise(); }); } return returnValue; }, }; }; //# sourceMappingURL=task-group.js.map