You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
327 B

  1. // @flow
  2. export default function debounce<T>(fn: Function): () => Promise<T> {
  3. let pending;
  4. return () => {
  5. if (!pending) {
  6. pending = new Promise<T>(resolve => {
  7. Promise.resolve().then(() => {
  8. pending = undefined;
  9. resolve(fn());
  10. });
  11. });
  12. }
  13. return pending;
  14. };
  15. }