change source
This commit is contained in:
parent
37beaa2d0e
commit
0d8ef15551
@ -7,8 +7,7 @@ Release: 1
|
|||||||
Summary: Run multiple promise-returning & async functions with limited concurrency
|
Summary: Run multiple promise-returning & async functions with limited concurrency
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://github.com/sindresorhus/p-limit
|
URL: https://github.com/sindresorhus/p-limit
|
||||||
Source0: https://registry.npmjs.org/%{packagename}/-/%{packagename}-%{version}.tgz
|
Source0: https://github.com/sindresorhus/p-limit/archive/v%{version}.tar.gz
|
||||||
Source1: https://raw.githubusercontent.com/sindresorhus/p-limit/v%{version}/test.js
|
|
||||||
ExclusiveArch: %{nodejs_arches} noarch
|
ExclusiveArch: %{nodejs_arches} noarch
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
BuildRequires: nodejs-packaging
|
BuildRequires: nodejs-packaging
|
||||||
@ -19,8 +18,7 @@ BuildRequires: npm(ava)
|
|||||||
Run multiple promise-returning & async functions with limited concurrency
|
Run multiple promise-returning & async functions with limited concurrency
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -n package
|
%autosetup -n p-limit-%{version}
|
||||||
cp -p %{SOURCE1} .
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
37
test.js
37
test.js
@ -1,37 +0,0 @@
|
|||||||
import test from 'ava';
|
|
||||||
import delay from 'delay';
|
|
||||||
import inRange from 'in-range';
|
|
||||||
import timeSpan from 'time-span';
|
|
||||||
import randomInt from 'random-int';
|
|
||||||
import m from './';
|
|
||||||
|
|
||||||
test('concurrency: 1', async t => {
|
|
||||||
const input = [
|
|
||||||
[10, 300],
|
|
||||||
[20, 200],
|
|
||||||
[30, 100]
|
|
||||||
];
|
|
||||||
|
|
||||||
const end = timeSpan();
|
|
||||||
const limit = m(1);
|
|
||||||
const mapper = ([val, ms]) => limit(() => delay(ms).then(() => val));
|
|
||||||
|
|
||||||
t.deepEqual(await Promise.all(input.map(mapper)), [10, 20, 30]);
|
|
||||||
t.true(inRange(end(), 590, 650));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('concurrency: 4', async t => {
|
|
||||||
const concurrency = 5;
|
|
||||||
let running = 0;
|
|
||||||
|
|
||||||
const limit = m(concurrency);
|
|
||||||
|
|
||||||
const input = Array(100).fill(0).map(() => limit(async () => {
|
|
||||||
running++;
|
|
||||||
t.true(running <= concurrency);
|
|
||||||
await delay(randomInt(30, 200));
|
|
||||||
running--;
|
|
||||||
}));
|
|
||||||
|
|
||||||
await Promise.all(input);
|
|
||||||
});
|
|
||||||
BIN
v1.1.0.tar.gz
Normal file
BIN
v1.1.0.tar.gz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user