-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removed detach * Included setTimeouts in tests * Fixed fake transport race * Rethrowing callback exceptions * Removed detach suite * Simplify FakeTransport changes and change autoTrigger behaviour * Added README explanation of withManualTrigger()
- Loading branch information
1 parent
18fb6cf
commit cd3cae9
Showing
11 changed files
with
97 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,3 @@ | ||
// awaitingExecution is null if there is no current timer | ||
let awaitingExecution: Array<() => void> | null = null; | ||
|
||
function runCallbacks() { | ||
if (awaitingExecution) { | ||
// Use a new reference to the awaitingExecution array to allow callbacks to add to the "new" awaitingExecution array | ||
const thisCallbackSet = awaitingExecution; | ||
awaitingExecution = null; | ||
for (let i = 0; i < thisCallbackSet.length; i++) { | ||
try { | ||
thisCallbackSet[i](); | ||
} catch (e) { | ||
if (awaitingExecution === null) { | ||
awaitingExecution = []; | ||
setTimeout(() => { | ||
runCallbacks(); | ||
}, 0); | ||
} | ||
// Add the remaining callbacks to the array so that they can be invoked on the next pass | ||
for (let k = thisCallbackSet.length - 1; k > i; k--) { | ||
awaitingExecution.unshift(thisCallbackSet[k]); | ||
} | ||
// rethrow the error | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// detach executes the callbacks in the order they are added with no context - this is used to avoid errors thrown | ||
// in user callbacks being caught by handlers such as fetch's catch. This function is necessary as setTimeout in | ||
// Safari is prone to switching the order of execution of setTimeout(0). | ||
export default function detach(cb: () => void) { | ||
if (awaitingExecution !== null) { | ||
// there is a timer running, add to the list and this function will be executed with that existing timer | ||
awaitingExecution.push(cb); | ||
return; | ||
} | ||
awaitingExecution = [cb]; | ||
setTimeout(() => { | ||
runCallbacks(); | ||
}, 0); | ||
cb(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.