Join 2 'threads' in javascript

前端 未结 6 1480
时光取名叫无心
时光取名叫无心 2021-01-05 06:44

If I have an ajax call off fetching (with a callback) and then some other code running in the meantime. How can I have a third function that will be called when both of the

6条回答
  •  滥情空心
    2021-01-05 07:19

    Something like this (schematic):

    registerThread() {
      counter++;
    }
    
    unregisterThread() {
      if (--counter == 0) fireEvent('some_user_event');
    }
    
    eventHandler_for_some_user_event() {
       do_stuff();
    }
    

提交回复
热议问题