Skip to content

Commit

Permalink
promise-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Evheniy Bystrov committed Feb 5, 2017
1 parent 26f16be commit 5565e99
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
src_dir: .
coverage_clover: coverage/coverage.raw.json
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
"env": {
"es6": true,
"node": true,
"mocha": true,
},
"globals": {
"fetch": true,
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
},
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1,
},
],
"linebreak-style": [
"error",
"unix",
],
"quotes": [
"error",
"single",
],
"semi": [
"error",
"always",
],
}
};
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage
.idea
npm-debug.log
node_modules
.DS_Store
3 changes: 3 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instrumentation:
default-excludes: true
include-all-sources: true
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 7
script:
- npm test && npm run report-coverage
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# promise-timeout
Promise timeout
===========================

It could be useful when you need to make pause in promise pipeline


[![Build Status](https://travis-ci.org/evheniy/promise-timeout.svg?branch=master)](https://travis-ci.org/evheniy/promise-timeout)
[![Coverage Status](https://coveralls.io/repos/github/evheniy/promise-timeout/badge.svg?branch=master)](https://coveralls.io/github/evheniy/promise-timeout?branch=master)


Installation
------------

npm i -S promise-timeout

Example
-------

const pause = require('promise-timeout');

(async () => {
const data1 = await fetch(url1);
await pause(1000);
const data2 = await fetch(url2);
})();
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = ms => new Promise(resolve => setTimeout(resolve, ms));
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "promise-timeout",
"description": "Promise timeout",
"repository": "evheniy/promise-timeout",
"version": "0.0.1",
"scripts": {
"test": "npm run security && npm run clear && npm run lint && npm run coverage",
"lint": "./node_modules/.bin/eslint index.js tests",
"coverage": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- tests --recursive",
"report-coverage": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"clear": "./node_modules/.bin/rimraf coverage",
"security": "./node_modules/.bin/nsp check"
},
"engines": {
"node": ">=7.0.0"
},
"keywords": [
"promise",
"timeout",
"setTimeout",
"async",
"await"
],
"files": [
"index.js"
],
"dependencies": {},
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "^2.11.15",
"eslint": "^3.14.1",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.2.0",
"nsp": "^2.6.2",
"rimraf": "^2.5.4"
},
"license": "MIT"
}
14 changes: 14 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const expect = require('chai').expect;
const promise = require('../index');


describe('Promise timeout test', () => {
it('it should test promise timeout', async () => {
const start = new Date;
await promise(1000);
const ms = new Date - start;

expect(ms).to.be.above(1000);
expect(ms).to.be.below(2000);
});
});

0 comments on commit 5565e99

Please sign in to comment.