Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

promise utils

You are probably better off using effect-js

concurrent

Just a Promise.all wrapper

concurrentLiteral

Similar to concurrent, but accepts and correctly types results based on an incoming object.

type Expected = { // this is inferred
  a: number;
  b: string;
  c: boolean;
};

const results: Expected = await concurrentLiteral({
  a: Promise.resolve(1),
  b: Promise.resolve('2'),
  c: Promise.resolve(true),
});

sequential

Accepts an array of promise factories and resolves them sequentially.

type Expected = [number, string, boolean]; // this is inferred

const results: Expected = await sequential([
  () => Promise.resolve(1),
  () => Promise.resolve('2'),
  () => Promise.resolve(true),
]);

// results: [1, '2', true] however '2' is not evaluated until 1 is resolved, and so on...

sequentialLiteral

Similar to sequential and concurrentLiteral, but accepts and correctly types results based on an incoming object.

type Expected = { // this is inferred
  a: number;
  b: string;
  c: boolean;
};

const results: Expected = await sequentialLiteral({
  a: () => Promise.resolve(1),
  b: () => Promise.resolve('2'),
  c: () => Promise.resolve(true),
});

The order in which this is resolved is based on Object.keys order.

concurrentChunked

Accepts an array of promise factories and resolves them concurrently in chunks, each chunk sequentially.

type Expected = [number, string, boolean]; // this is inferred

const results: Expected = await concurrentChunked(
  2,
  () => Promise.resolve(1),     // frame 1
  () => Promise.resolve('2'),   // frame 1
  () => Promise.resolve(true),  // frame 2
);

Frames with the same index will be concurrently resolved, sequentially related to every other frame.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages