-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.js
1 lines (1 loc) · 4.24 KB
/
task.js
1
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.task=n()}}(function(){return function n(t,o,r){function u(i,f){if(!o[i]){if(!t[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(e)return e(i,!0);var p=new Error("Cannot find module '"+i+"'");throw p.code="MODULE_NOT_FOUND",p}var a=o[i]={exports:{}};t[i][0].call(a.exports,function(n){var o=t[i][1][n];return u(o?o:n)},a,a.exports,n,t,o,r)}return o[i].exports}for(var e="function"==typeof require&&require,i=0;i<r.length;i++)u(r[i]);return u}({1:[function(require,n,exports){"use strict";var t=require("./task");n.exports=t},{"./task":2}],2:[function(require,n,exports){"use strict";function t(n,t){this._run=t?r(n):o(n)}function o(n){return function(t,o){return n(t,o)||e}}function r(n){return function(t,o){var r=!1,u=n(function(n){r||(r=!0,t(n))},function(n){r||(r=!0,o(n))});return function(){r||(r=!0,u&&u())}}}function u(n){return new t(n,!0)}function e(){}function i(n){return function(t){if(t&&"function"==typeof t[n])return t[n]()}}function f(n){return function t(o,r){return 1===arguments.length?p(t,o):r&&"function"==typeof r[n]?r[n](o):void 0}}function c(n){return function t(o,r,u){return 1===arguments.length?p(t,o):2===arguments.length?a(t,o,r):u&&"function"==typeof u[n]?u[n](o,r):void 0}}function p(n,t){return function(o,r,u){switch(arguments.length){case 1:return n(t,o);case 2:return n(t,o,r);default:return n(t,o,r,u)}}}function a(n,t,o){return function(r,u){return 1===arguments.length?n(t,o,r):n(t,o,r,u)}}t.prototype.run=function(n,t){return this._run(n,t)},t.prototype["@@type"]="jordalgo/task",t.prototype.map=function(n){var o=this;return new t(function(t,r){return o.run(t,function(t){r(n(t))})})},t.prototype.bimap=function(n,o){var r=this;return new t(function(t,u){return r.run(function(o){t(n(o))},function(n){u(o(n))})})},t.prototype.chain=function(n){var o=this;return new t(function(t,r){var u=void 0,e=o.run(t,function(o){u=n(o).run(t,r)});return function(){e(),u&&u()}})},t.prototype.bichain=function(n,o){var r=this;return new t(function(t,u){var e=void 0,i=r.run(function(o){e=n(o).run(t,u)},function(n){e=o(n).run(t,u)});return function(){i(),e&&e()}})},t.prototype.ap=function(n){var o=this;return new t(function(t,r){function u(n){e||(e=!0,t(n))}var e=void 0,i=void 0,f=void 0,c=void 0,p=n.run(u,function(n){i?r(c(n)):(i=!0,f=n)}),a=o.run(u,function(n){i?r(n(f)):(i=!0,c=n)});return function(){p(),a()}})},t.prototype.concat=function(n){var o=this;return new t(function(t,r){function u(n){i||(i=!0,t(n))}function e(n){i||(i=!0,r(n))}var i=void 0,f=n.run(u,e),c=o.run(u,e);return function(){f(),c()}})},t.prototype.cache=function(){var n=!1,o=!1,r=void 0,u=void 0,i=[],f=[],c=this;return new t(function(t,p){return n&&o?("fail"===o?t(r):p(u),e):n?(f.indexOf(t)===-1&&f.push(t),void(i.indexOf(p)===-1&&i.push(p))):(n=!0,i.push(p),f.push(t),c.run(function(n){o="fail",r=n,f.forEach(function(t){t(n)}),f=[]},function(n){o="success",u=n,i.forEach(function(t){t(n)}),i=[]}))})},t.prototype.of=function(n){return new t(function(t,o){o(n)})},t.prototype.fail=function(n){return new t(function(t){t(n)})},t.prototype.empty=function(){return new t(function(){})},t.prototype.toString=function(){return"Task"},t.prototype.fork=t.prototype.run,t.prototype.callback=function(n){return this.run(function(t){n(t)},function(t){n(null,t)})},t.prototype.orElse=function(n){var o=this;return new t(function(t,r){return o.run(function(){r(n)},r)})},u.chain=f("chain"),u.bichain=c("bichain"),u.map=f("map"),u.bimap=c("bimap"),u.ap=f("ap"),u.concat=f("concat"),u.cache=i("cache"),u.orElse=f("orElse"),u.of=t.prototype.of,u.fail=t.prototype.fail,u.empty=t.prototype.empty,u.after=function(n,o){return new t(function(t,r){var u=setTimeout(function(){r(o)},n);return function(){clearTimeout(u)}})},u.all=function(n){function o(){u=[],r=[],e=!0}var r=[],u=[],e=!1;return new t(function(t,i){n.forEach(function(f){var c=f.run(function(n){e||(u.forEach(function(n){n()}),t(n),o())},function(t){e||(r.push(t),r.length===n.length&&(i(r),o()))});return u.push(c),function(){u.forEach(function(n){n()})}})})},n.exports=u},{}]},{},[1])(1)});