package init
This commit is contained in:
parent
bee76d804f
commit
73dd122d2e
49
nodejs-p-limit.spec
Normal file
49
nodejs-p-limit.spec
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
%{?nodejs_find_provides_and_requires}
|
||||||
|
%global packagename p-limit
|
||||||
|
%global enable_tests 0
|
||||||
|
Name: nodejs-p-limit
|
||||||
|
Version: 1.1.0
|
||||||
|
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
|
||||||
|
ExclusiveArch: %{nodejs_arches} noarch
|
||||||
|
BuildArch: noarch
|
||||||
|
BuildRequires: nodejs-packaging
|
||||||
|
%if 0%{?enable_tests}
|
||||||
|
BuildRequires: npm(ava)
|
||||||
|
%endif
|
||||||
|
%description
|
||||||
|
Run multiple promise-returning & async functions with limited concurrency
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%autosetup -n package
|
||||||
|
cp -p %{SOURCE1} .
|
||||||
|
|
||||||
|
%build
|
||||||
|
|
||||||
|
%install
|
||||||
|
mkdir -p %{buildroot}%{nodejs_sitelib}/%{packagename}
|
||||||
|
cp -pr package.json index.js \
|
||||||
|
%{buildroot}%{nodejs_sitelib}/%{packagename}
|
||||||
|
%nodejs_symlink_deps
|
||||||
|
|
||||||
|
%check
|
||||||
|
%nodejs_symlink_deps --check
|
||||||
|
%{__nodejs} -e 'require("./")'
|
||||||
|
%if 0%{?enable_tests}
|
||||||
|
%{_bindir}/ava
|
||||||
|
%else
|
||||||
|
%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m"
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%files
|
||||||
|
%doc readme.md
|
||||||
|
%license license
|
||||||
|
%{nodejs_sitelib}/%{packagename}
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Mon Aug 31 2020 wutao <wutao61@huawei.com> - 1.1.0-1
|
||||||
|
- Package init
|
||||||
BIN
p-limit-1.1.0.tgz
Normal file
BIN
p-limit-1.1.0.tgz
Normal file
Binary file not shown.
37
test.js
Normal file
37
test.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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);
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user