Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

38 строки
492 B

  1. let lastId = 0;
  2. const list = [];
  3. const complete = id => {
  4. list.spliceWhere(l => l === id);
  5. };
  6. const register = () => {
  7. const nextId = ++lastId;
  8. list.push(nextId);
  9. return complete.bind(null, nextId);
  10. };
  11. const returnWhenDone = async () => {
  12. if (!list.length)
  13. return;
  14. return new Promise(res => {
  15. const checker = () => {
  16. if (!list.length) {
  17. res();
  18. return;
  19. }
  20. setTimeout(checker, 100);
  21. };
  22. checker();
  23. });
  24. };
  25. module.exports = {
  26. register,
  27. returnWhenDone
  28. };