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.

14 lines
302 B

2 months ago
  1. export default function debounce(fn) {
  2. var pending;
  3. return function () {
  4. if (!pending) {
  5. pending = new Promise(function (resolve) {
  6. Promise.resolve().then(function () {
  7. pending = undefined;
  8. resolve(fn());
  9. });
  10. });
  11. }
  12. return pending;
  13. };
  14. }