Skip to content

get something asynchronously without repetition

License

Notifications You must be signed in to change notification settings

yiminghe/get-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

get something asynchronously without repetition

Resources

License

Stars

Watchers

Forks

Packages

No packages published