// Setup the timeout handlervar timeoutProtect = setTimeout(function() { // Clear the local timer variable, indicating the timeout has been triggered. timeoutProtect = null; // Execute the callback with an error argument. callback({error:'async timed out'});}, 5000);// Call the async functionasyncFunction(arguments, function() { // Proceed only if the timeout handler has not yet fired. if (timeoutProtect) { // Clear the scheduled timeout handler clearTimeout(timeoutProtect); // Run the real callback. callback(); }});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)