第三方JS插件发出一个可以监听的事件:
jsInt.on('ready', function(services) {
if(Array.isArray(services) && ~services.indexOf('magic')) {
//integration is ready to use and it has 'magic' service available
} else {
//integration is ready to use but it does not have 'magic' service
}
});
如何以编程方式检测3秒钟内是否没有发生此事件?
答案 0 :(得分:4)
让on
回调取消一个超时,该超时在3秒后运行:
const timeoutId = setTimeout(() => {
console.log('Library did not load in time!');
// ...handle the problem
}, 3000);
jsInt.on('ready', function(services) {
clearTimeout(timeoutId);
// rest of the code
if(Array.isArray(services) && ~services.indexOf('magic')) {
//integration is ready to use and it has 'magic' service available
} else {
//integration is ready to use but it does not have 'magic' service
}
});
答案 1 :(得分:0)
这就是诺言。
<p>