Skip to content

Commit

Permalink
Merge 50817f9 into 6b75d94
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Jan 20, 2021
2 parents 6b75d94 + 50817f9 commit 5cfcb65
Show file tree
Hide file tree
Showing 12 changed files with 5,646 additions and 297 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [ForbesLindesay]
patreon: ForbesLindesay
open_collective: # Replace with an open collevite username
ko_fi: # Replace with a single Ko-fi username
tidelift: # npm/@forbeslindesay/npm-package-template
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with a single custom sponsorship URL
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: 'bug:'
labels: bug
assignees: ''
---

**Describe the bug**

A clear and concise description of what the bug is.

**To Reproduce**

Steps to reproduce the behaviour:

**Expected behaviour**

A clear and concise description of what you expected to happen.

**Versions**

- node version:
- npm/yarn version:
- package version:

**Additional context**

Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'feat:'
labels: enhancement
assignees: ''
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/other_question.md
@@ -0,0 +1,7 @@
---
name: Any Other question
about: Use this for questions that are not bugs or feature requests
title: ''
labels: question
assignees: ''
---
36 changes: 36 additions & 0 deletions .github/workflows/rollingversions.yml
@@ -0,0 +1,36 @@
name: Release

on:
repository_dispatch:
types: [rollingversions_publish_approved]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run test

publish:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npx rollingversions publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,52 @@
name: Test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run test
- run: npm run coverage
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.node-version }}
parallel: true

finish_coveralls:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true

test_browsers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.x
- run: npm install
- run: node test/browser.js
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

153 changes: 70 additions & 83 deletions index.js
@@ -1,96 +1,87 @@
'use strict';

module.exports = function (PromiseArgument) {
var Promise;
function throat(size, fn) {
var queue = new Queue();
function run(fn, self, args) {
if (size) {
size--;
var result = new Promise(function (resolve) {
resolve(fn.apply(self, args));
var fakeResolvedPromise = {
then: function (fn) {
return fn();
},
};
module.exports = function throat(size, fn) {
var queue = new Queue();
function run(fn, self, args) {
var ready = size
? fakeResolvedPromise
: new Promise(function (resolve) {
queue.push(resolve);
});
result.then(release, release);
return result;
} else {
if (size) {
size--;
}
return ready
.then(function () {
return new Promise(function (resolve) {
queue.push(new Delayed(resolve, fn, self, args));
resolve(fn.apply(self, args));
});
}
}
function release() {
size++;
if (!queue.isEmpty()) {
var next = queue.shift();
next.resolve(run(next.fn, next.self, next.args));
}
}
if (typeof size === 'function') {
var temp = fn;
fn = size;
size = temp;
}
if (typeof size !== 'number') {
throw new TypeError(
'Expected throat size to be a number but got ' + typeof size
);
}
if (fn !== undefined && typeof fn !== 'function') {
throw new TypeError(
'Expected throat fn to be a function but got ' + typeof fn
);
}
if (typeof fn === 'function') {
return function () {
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
})
.then(
function (result) {
release();
return result;
},
function (err) {
release();
throw err;
}
return run(fn, this, args);
};
);
}
function release() {
var next = queue.shift();
if (next) {
next();
} else {
return function (fn) {
if (typeof fn !== 'function') {
throw new TypeError(
'Expected throat fn to be a function but got ' + typeof fn
);
}
var args = [];
for (var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
}
return run(fn, this, args);
};
size++;
}
}
if (arguments.length === 1 && typeof PromiseArgument === 'function') {
Promise = PromiseArgument;
return throat;
if (typeof size === 'function') {
var temp = fn;
fn = size;
size = temp;
}
if (typeof size !== 'number') {
throw new TypeError(
'Expected throat size to be a number but got ' + typeof size
);
}
if (fn !== undefined && typeof fn !== 'function') {
throw new TypeError(
'Expected throat fn to be a function but got ' + typeof fn
);
}
if (typeof fn === 'function') {
return function () {
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
return run(fn, this, args);
};
} else {
Promise = module.exports.Promise;
if (typeof Promise !== 'function') {
throw new Error(
'You must provide a Promise polyfill for this library to work in older environments'
);
}
return throat(arguments[0], arguments[1]);
return function (fn) {
if (typeof fn !== 'function') {
throw new TypeError(
'Expected throat fn to be a function but got ' + typeof fn
);
}
var args = [];
for (var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
}
return run(fn, this, args);
};
}
};

module.exports.default = module.exports;

/* istanbul ignore next */
if (typeof Promise === 'function') {
module.exports.Promise = Promise;
}

function Delayed(resolve, fn, self, args) {
this.resolve = resolve;
this.fn = fn;
this.self = self || null;
this.args = args;
}

function Queue() {
this._s1 = [];
this._s2 = [];
Expand All @@ -105,14 +96,10 @@ Queue.prototype.shift = function () {
if (s2.length === 0) {
var s1 = this._s1;
if (s1.length === 0) {
return;
return undefined;
}
this._s1 = s2;
s2 = this._s2 = s1.reverse();
}
return s2.pop();
};

Queue.prototype.isEmpty = function () {
return !this._s1.length && !this._s2.length;
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,7 +33,7 @@
"scripts": {
"tsc": "tsc --noEmit",
"flow": "flow",
"test": "node test/index.js && npm run test:types && node test/browser.js",
"test": "node test/index.js && npm run test:types",
"test:types": "jest",
"coverage": "istanbul cover test/index.js",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls"
Expand Down

0 comments on commit 5cfcb65

Please sign in to comment.