@9wick/serial-executor
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Serial Execute async functions

install

npm i @9wick/serial-exeecutor

How to use

  import {createSerialExecutor} from "@9wick/serial-executor"
  const wait = (ms: number) => {
    return new Promise(resolve => setTimeout(resolve, ms));
  }
  
  const executor = createSerialExecutor();
  const p1 =  executor.execute(async () => {
    await wait(100);
    console.log("first queue");
    return 4;
  });
  const p2 = executor.execute(async () => {
    await wait(10);
    console.log("second queue");
    return 5;
  });

  const [r1,r2] = await Promise.all([p1,p2]);
  expect(r1).toEqual(4);
  expect(r2).toEqual(5);

Readme

Keywords

none

Package Sidebar

Install

npm i @9wick/serial-executor

Weekly Downloads

28

Version

1.0.0

License

MIT

Unpacked Size

31.9 kB

Total Files

17

Last publish

Collaborators

  • kido