Skip to content

Commit c698360

Browse files
committed
v3.8.0
1 parent d1cf291 commit c698360

File tree

16 files changed

+114
-34
lines changed

16 files changed

+114
-34
lines changed

dist/README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Transpiled code is wrapped in [UMD](https://davidbcalhoun.com/2014/what-is-amd-c
4343
- [singular](#singular)
4444
- [waitFor](#waitfor)
4545
- [rerun](#rerun)
46-
- [promiseAll](#promiseAll)
46+
- [delay](#delay)
47+
- [promiseAll](#promiseall)
4748
- [promisify](#promisify)
4849
- [promisify.all](#promisifyall)
4950
- [collar](#collar)
@@ -115,6 +116,7 @@ last(persons, (p) => p.name === 'no-name') // => undefined
115116

116117

117118
### empty
119+
118120
Remove all items from 1 or more provided arrays.
119121

120122
```javascript
@@ -252,15 +254,15 @@ waitFor((abort) => {
252254
253255
### rerun
254256
255-
If you think of using setInterval stop and use rerun! For more info on usage reference unit tests ot source code.
257+
setInterval on steroids.
256258
257259
```javascript
258260

259261
// Any user defined function.
260262
rerun(Function)
261263
// How frequently will rerun function be called
262-
.every(timeInMiliseconds)
263-
// [Optional] Execution is stoped if falsy value is returned from function. If falsy value is returned first time rerun will never be called.
264+
.every(timeInMilliseconds)
265+
// [Optional] Execution is stopped if falsy value is returned from function. If falsy value is returned first time rerun will never be called.
264266
.asLongAs(Function)
265267
// Execute rerun function for first time and start execution cycle
266268
.start()
@@ -279,14 +281,32 @@ If you think of using setInterval stop and use rerun! For more info on usage ref
279281
// Function that will be called after user log in
280282
// Every call to start will execute function immediately and restart execution cycle
281283
eventBus.$on('login', refreshTokenRunner.start);
284+
```
285+
286+
## delay
287+
288+
Delay a promise a specified amount of time. Think of it as setTimeout for async flow
289+
290+
```javascript
291+
const delay = require('js-flock/delay');
292+
293+
async exampleFunction() {
294+
bar();
295+
296+
// Wait for 100 milliseconds
297+
// If delay time not provided it defaults ot 0ms (next tick)
298+
await delay(100);
282299

300+
// Executed 100 milliseconds later
301+
baz();
302+
}
283303
```
284304
285305
### promiseAll
286306
287307
Alias for `Promise.all` that works on objects and arrays
288308
289-
```js
309+
```javascript
290310
const promiseAll = require('js-flock/promiseAll');
291311

292312
const objectResponse = await promiseAll({

dist/delay.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// >>> PUBLIC <<<
2+
3+
module.exports = function(numberOfMs = 0) {
4+
const delay = Number(numberOfMs);
5+
if (Number.isNaN(delay)) {
6+
const tag = Object.prototype.toString.call(numberOfMs);
7+
throw new TypeError(`delay: expected [Number] but got ${tag}`);
8+
}
9+
10+
return new Promise((resolve) => {
11+
setTimeout(resolve, numberOfMs);
12+
});
13+
};

dist/es5/delay.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global.delay = global.delay || {}, global.delay.js = factory());
5+
}(this, (function () { 'use strict';
6+
7+
// >>> PUBLIC <<<
8+
9+
var delay = function delay() {
10+
var numberOfMs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
11+
12+
var delay = Number(numberOfMs);
13+
if (Number.isNaN(delay)) {
14+
var tag = Object.prototype.toString.call(numberOfMs);
15+
throw new TypeError("delay: expected [Number] but got " + tag);
16+
}
17+
18+
return new Promise(function (resolve) {
19+
setTimeout(resolve, numberOfMs);
20+
});
21+
};
22+
23+
return delay;
24+
25+
})));

dist/es5/delay.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es5/index.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ var deepSeal = function deepSeal(obj, options) {
144144

145145
// >>> PUBLIC <<<
146146

147+
var delay = function delay() {
148+
var numberOfMs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
149+
150+
var delay = Number(numberOfMs);
151+
if (Number.isNaN(delay)) {
152+
var tag = Object.prototype.toString.call(numberOfMs);
153+
throw new TypeError("delay: expected [Number] but got " + tag);
154+
}
155+
156+
return new Promise(function (resolve) {
157+
setTimeout(resolve, numberOfMs);
158+
});
159+
};
160+
161+
// >>> PUBLIC <<<
162+
147163
/**
148164
* Remove all items from array
149165
* @param {Array[]} props - 1 or more arrays to empty out
@@ -217,7 +233,7 @@ var assertType = function assertType(moduleName) {
217233
var throwError = type === 'Function' ? typeof val !== 'function' : '[object ' + type + ']' !== tag;
218234

219235
if (throwError) {
220-
throw new TypeError(moduleName + ': expected [' + type + '] but got ' + tag + ']');
236+
throw new TypeError(moduleName + ': expected [' + type + '] but got ' + tag);
221237
}
222238
};
223239
};
@@ -728,6 +744,7 @@ var src = {
728744
deepFreeze: deepFreeze,
729745
deepPreventExtensions: deepPreventExtensions,
730746
deepSeal: deepSeal,
747+
delay: delay,
731748
empty: empty,
732749
last: last,
733750
promiseAll: promiseAll,
@@ -743,30 +760,32 @@ var src_1 = src.collar;
743760
var src_2 = src.deepFreeze;
744761
var src_3 = src.deepPreventExtensions;
745762
var src_4 = src.deepSeal;
746-
var src_5 = src.empty;
747-
var src_6 = src.last;
748-
var src_7 = src.promiseAll;
749-
var src_8 = src.promisify;
750-
var src_9 = src.rerun;
751-
var src_10 = src.singular;
752-
var src_11 = src.sort;
753-
var src_12 = src.toEnum;
754-
var src_13 = src.waitFor;
763+
var src_5 = src.delay;
764+
var src_6 = src.empty;
765+
var src_7 = src.last;
766+
var src_8 = src.promiseAll;
767+
var src_9 = src.promisify;
768+
var src_10 = src.rerun;
769+
var src_11 = src.singular;
770+
var src_12 = src.sort;
771+
var src_13 = src.toEnum;
772+
var src_14 = src.waitFor;
755773

756774
exports['default'] = src;
757775
exports.collar = src_1;
758776
exports.deepFreeze = src_2;
759777
exports.deepPreventExtensions = src_3;
760778
exports.deepSeal = src_4;
761-
exports.empty = src_5;
762-
exports.last = src_6;
763-
exports.promiseAll = src_7;
764-
exports.promisify = src_8;
765-
exports.rerun = src_9;
766-
exports.singular = src_10;
767-
exports.sort = src_11;
768-
exports.toEnum = src_12;
769-
exports.waitFor = src_13;
779+
exports.delay = src_5;
780+
exports.empty = src_6;
781+
exports.last = src_7;
782+
exports.promiseAll = src_8;
783+
exports.promisify = src_9;
784+
exports.rerun = src_10;
785+
exports.singular = src_11;
786+
exports.sort = src_12;
787+
exports.toEnum = src_13;
788+
exports.waitFor = src_14;
770789

771790
Object.defineProperty(exports, '__esModule', { value: true });
772791

dist/es5/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es5/promisify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var assertType = function assertType(moduleName) {
1717
var throwError = type === 'Function' ? typeof val !== 'function' : '[object ' + type + ']' !== tag;
1818

1919
if (throwError) {
20-
throw new TypeError(moduleName + ': expected [' + type + '] but got ' + tag + ']');
20+
throw new TypeError(moduleName + ': expected [' + type + '] but got ' + tag);
2121
}
2222
};
2323
};

dist/es5/promisify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es5/rerun.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var assertType$1 = function assertType(moduleName) {
1313
var throwError = type === 'Function' ? typeof val !== 'function' : '[object ' + type + ']' !== tag;
1414

1515
if (throwError) {
16-
throw new TypeError(moduleName + ': expected [' + type + '] but got ' + tag + ']');
16+
throw new TypeError(moduleName + ': expected [' + type + '] but got ' + tag);
1717
}
1818
};
1919
};

dist/es5/rerun.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)