0.1.6 • Published 4 years ago
get-async v0.1.6
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);