我不熟悉执行此操作的任何库,但连接起来并不难。
// 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(); }});


