change source

This commit is contained in:
jackie_wu 2020-09-08 16:28:50 +08:00
parent 37beaa2d0e
commit 0d8ef15551
4 changed files with 2 additions and 41 deletions

View File

@ -7,8 +7,7 @@ Release: 1
Summary: Run multiple promise-returning & async functions with limited concurrency
License: MIT
URL: https://github.com/sindresorhus/p-limit
Source0: https://registry.npmjs.org/%{packagename}/-/%{packagename}-%{version}.tgz
Source1: https://raw.githubusercontent.com/sindresorhus/p-limit/v%{version}/test.js
Source0: https://github.com/sindresorhus/p-limit/archive/v%{version}.tar.gz
ExclusiveArch: %{nodejs_arches} noarch
BuildArch: noarch
BuildRequires: nodejs-packaging
@ -19,8 +18,7 @@ BuildRequires: npm(ava)
Run multiple promise-returning & async functions with limited concurrency
%prep
%autosetup -n package
cp -p %{SOURCE1} .
%autosetup -n p-limit-%{version}
%build

Binary file not shown.

37
test.js
View File

@ -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

Binary file not shown.