Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 523 Bytes

README.md

File metadata and controls

34 lines (25 loc) · 523 Bytes

get-async

get something asynchronously without repetition

usage

import getAsync from 'get-async';

let called = 0;

function getTimer() {
  called++;
  return new Promise<number>(resolve => {
    setTimeout(() => {
      resolve(called);
    }, 100);
  });
}

const call1 = getAsync<number>('timer', getTimer);

const call2 = getAsync<number>('timer', getTimer);

const ret = await Promise.all([call1, call2]);

expect(ret).toMatchInlineSnapshot(`
  Array [
    1,
    1,
  ]
`);
expect(called).toBe(1);