Merge branch 'master' into 'master'

Implement smartdelay

See merge request !1
This commit is contained in:
Phil Kunz 2017-01-17 17:33:20 +00:00
commit 431f4f7169
9 changed files with 119 additions and 1 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
node_modules/
docs/
coverage/
public/

View File

@ -21,4 +21,13 @@ timeouts for the async/await era, written in TypeScript
## Usage
Use TypeScript for best in class instellisense.
```javascript
import * as smartdelay from 'smartdelay'
(async () => {
await smartdelay.delayFor('3000') // excution will halt here 3 seconds for this function scope BUT NOT BLOCK anything else
console.log()
})()
```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

2
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
import 'typings-global';
export declare let delayFor: <T>(timeInMillisecond: number, passOn?: T) => Promise<T>;

19
dist/index.js vendored Normal file
View File

@ -0,0 +1,19 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
require("typings-global");
exports.delayFor = (timeInMillisecond, passOn) => __awaiter(this, void 0, void 0, function* () {
yield new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, timeInMillisecond);
});
return passOn;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSwwQkFBdUI7QUFFWixRQUFBLFFBQVEsR0FBRyxDQUFVLGlCQUF5QixFQUFFLE1BQVU7SUFDakUsTUFBTSxJQUFJLE9BQU8sQ0FBQyxDQUFDLE9BQU8sRUFBRSxNQUFNO1FBQzlCLFVBQVUsQ0FDTjtZQUNJLE9BQU8sRUFBRSxDQUFBO1FBQ2IsQ0FBQyxFQUNELGlCQUFpQixDQUNwQixDQUFBO0lBQ0wsQ0FBQyxDQUFDLENBQUE7SUFDRixNQUFNLENBQUMsTUFBTSxDQUFBO0FBQ2pCLENBQUMsQ0FBQSxDQUFBIn0=

View File

@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "timeouts for the async/await era, written in TypeScript",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)"
},
@ -15,5 +16,13 @@
"bugs": {
"url": "https://gitlab.com/pushrocks/smartdelay/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartdelay#README"
"homepage": "https://gitlab.com/pushrocks/smartdelay#README",
"dependencies": {
"typings-global": "^1.0.14"
},
"devDependencies": {
"@types/should": "^8.1.30",
"should": "^11.1.2",
"typings-test": "^1.0.3"
}
}

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

30
test/test.js Normal file
View File

@ -0,0 +1,30 @@
"use strict";
require("typings-test");
const should = require("should");
const smartdelay = require("../dist/index");
describe('smartdelay', function () {
it('.delayFor should delay async', function (done) {
this.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
smartdelay.delayFor(3000).then(() => {
should(timePassed).be.true();
done();
});
});
it('.delayFor should pass on a type', function (done) {
this.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
let hey = 'heyThere';
smartdelay.delayFor(3000, hey).then((stringArg) => {
should(stringArg).equal('heyThere');
done();
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFx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UNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

31
test/test.ts Normal file
View File

@ -0,0 +1,31 @@
import 'typings-test'
import * as should from 'should'
import * as smartdelay from '../dist/index'
describe('smartdelay', function () {
it('.delayFor should delay async', function(done) {
this.timeout(5000)
let timePassed = false
setTimeout(() => {
timePassed = true
},2000)
smartdelay.delayFor(3000).then(() => {
should(timePassed).be.true()
done()
})
})
it('.delayFor should pass on a type', function(done) {
this.timeout(5000)
let timePassed = false
setTimeout(() => {
timePassed = true
},2000)
let hey = 'heyThere'
smartdelay.delayFor<string>(3000, hey).then((stringArg) => {
should(stringArg).equal('heyThere')
done()
})
})
})

13
ts/index.ts Normal file
View File

@ -0,0 +1,13 @@
import 'typings-global'
export let delayFor = async <T>(timeInMillisecond: number, passOn?: T) => {
await new Promise((resolve, reject) => {
setTimeout(
() => {
resolve()
},
timeInMillisecond
)
})
return passOn
}