Skip to content

Commit

Permalink
feat: Add function.microtaskDelay method
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Mar 16, 2018
1 parent 8d5a45c commit 66481c0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions function/#/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
copy: require("./copy"),
curry: require("./curry"),
lock: require("./lock"),
microtaskDelay: require("./microtask-delay"),
not: require("./not"),
partial: require("./partial"),
spread: require("./spread"),
Expand Down
14 changes: 14 additions & 0 deletions function/#/microtask-delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

var ensurePlainFunction = require("../../object/ensure-plain-function")
, defineLength = require("../_define-length")
, nextTick = require("next-tick");

var apply = Function.prototype.apply;

module.exports = function () {
var src = ensurePlainFunction(this);
return defineLength(function () {
nextTick(apply.bind(src, this, arguments));
}, this.length);
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"dependencies": {
"es6-iterator": "~2.0.3",
"es6-symbol": "~3.1.1"
"es6-symbol": "~3.1.1",
"next-tick": "1"
},
"devDependencies": {
"eslint": "^4.15",
Expand Down
22 changes: 22 additions & 0 deletions test/function/#/microtask-delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

var nextTick = require("next-tick");

module.exports = function (t, a, d) {
var wasInvoked = false, args = [{}, {}], context = {};
var target = t.call(function () {
a(this, context);
a.deep(arguments, args);
wasInvoked = true;
});

nextTick(function () {
a(wasInvoked, false);
target.apply(context, args);
a(wasInvoked, false);
nextTick(function () {
a(wasInvoked, true);
d();
});
});
};

0 comments on commit 66481c0

Please sign in to comment.