Skip to content

Commit

Permalink
Add TypeScript definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
zewish committed Mar 21, 2021
1 parent b17039a commit 12af381
Show file tree
Hide file tree
Showing 9 changed files with 1,010 additions and 168 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf

indent_style = space
indent_size = 2

trim_trailing_whitespace = true
insert_final_newline = true
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
check-latest: true
- run: npm install
- run: npm test
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

59 changes: 28 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[![NPM version](https://img.shields.io/npm/v/prottle.svg?style=flat-square)](https://www.npmjs.com/package/prottle)
[![Build Status](https://travis-ci.org/zewish/prottle.svg?branch=master)](https://travis-ci.org/zewish/prottle)
[![Build Status](https://github.com/zewish/prottle/workflows/build/badge.svg)](https://github.com/zewish/prottle/actions?query=workflow%3Abuild)
[![Downloads](https://img.shields.io/npm/dm/prottle.svg?style=flat-square)](https://www.npmjs.com/package/prottle)

Promise.all() throttle - Prottle

- Executes promise-returning functions in batches;
- Once batch 1 is finished it's time for the next one;
- Backend - Node 4.0+ supported;
- Frontend - works with ES2015 preset using babelify. Use a Promise polyfill for IE.
- Frontend - works with the env preset using babel. Use a Promise polyfill for IE.

Installation
------------
Expand All @@ -18,54 +18,51 @@ $ npm install prottle --save
Example - resolved
------------------
```js
'use strict';
let prottle = require('prottle');
const prottle = require('prottle');

prottle(2, [
// batch 1
() => Promise.resolve(1)
, () => Promise.resolve(2)
// batch 2
, () => Promise.resolve(3)
, () => new Promise((resolve, reject) => {
setTimeout(() => resolve(4), 3000);
})
// batch 3
, () => Promise.resolve(5)
// batch 1
() => Promise.resolve(1),
() => Promise.resolve(2),
// batch 2
() => Promise.resolve(3),
() => new Promise((resolve, reject) => {
setTimeout(() => resolve(4), 3000);
}),
// batch 3
() => Promise.resolve(5),
])
.then(res => {
.then(res => {
console.log(res); // [ 1, 2, 3, 4, 5 ]
});
});
```

Example - rejected
------------------
```js
'use strict';
let prottle = require('prottle');
const prottle = require('prottle');

prottle(2, [
() => Promise.resolve('yay')
, () => Promise.reject('beep boop')
, () => Promise.resolve('wow')
() => Promise.resolve('yay'),
() => Promise.reject('beep boop'),
() => Promise.resolve('wow')
])
.catch(err => {
.catch(err => {
console.log(err); // beep boop
});
});
```

Works with returned values too!
-------------------------------
```js
'use strict';
let prottle = require('prottle');
const prottle = require('prottle');

prottle(2, [
() => 1
, () => 2
, () => 3
() => 1,
() => 2,
() => 3
])
.then(res => {
.then(res => {
console.log(res); // [ 1, 2, 3 ]
});
```
});
```
Loading

0 comments on commit 12af381

Please sign in to comment.