Skip to content

zhaogongchengsi/promise-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise-kit

npm version bundle JSDocs

Some promise extension functions

Install

use pnpm to install

npm i @zunh/promise-kit
pnpm add @zunh/promise-kit

API

withTimeout

await withTimeout(Promise.resolve('success'), 1000)

withResolvers

const { resolve, promise } = withResolvers<string>();
resolve('success');
const result = await promise;

withRetry

await withRetry(async () => {
  return 'success';
}, 3, 1000);

forEach

await forEach([1, 2, 3], async (item) => {
  item + 1;
});

map

const result = await map([1, 2, 3], async (item) => {
  return item + 1;
});

parallel

await parallel([1,2,3], async () => {}, 2);

sleep

await sleep(1000);

randomSleep

await randomSleep(1000, 2000);

Task

const { run, waitComplete, pause, resume } = createTask([1,2,4])

run(async (item) => {
  return item + 1;
})

pause()

resume()

const result = await waitComplete()

License

MIT License © 2023-PRESENT zhaozunhong

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published