Asynchronously delay JS until a condition is met

后端 未结 3 1263
太阳男子
太阳男子 2021-02-06 01:45

I have a class, ChatRoom, that can only render after it receives a long-running HTTP request (it could take 1 second or 30 seconds). So I need to delay rendering un

3条回答
  •  没有蜡笔的小新
    2021-02-06 02:03

    You could also achieve this using lodash's debouncer with recursion.

    import _debounce from 'lodash/debounce';
    
    const wait = (() => {
        if ( chatroom.json ) {
            chatroom.render();
        } else {
          _debounce(wait, 500)();
        }
    })();

提交回复
热议问题