Skip to content

Commit

Permalink
add missing return statement (#38128)
Browse files Browse the repository at this point in the history
* add missing return statement

if abort has already been signaled, this function should not continue making a request or setting up an event listener

* Fix another

---------

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
  • Loading branch information
mindplay-dk and Josh-Cena authored Feb 12, 2025
1 parent b8f4535 commit 594eb75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function alarm(person, delay) {
return new Promise((resolve, reject) => {
if (delay < 0) {
reject(new Error("Alarm delay must not be negative"));
return;
}
setTimeout(() => {
resolve(`Wake up, ${person}!`);
Expand Down Expand Up @@ -132,6 +133,7 @@ function alarm(person, delay) {
return new Promise((resolve, reject) => {
if (delay < 0) {
reject(new Error("Alarm delay must not be negative"));
return;
}
setTimeout(() => {
resolve(`Wake up, ${person}!`);
Expand Down Expand Up @@ -190,6 +192,7 @@ function alarm(person, delay) {
return new Promise((resolve, reject) => {
if (delay < 0) {
reject(new Error("Alarm delay must not be negative"));
return;
}
setTimeout(() => {
resolve(`Wake up, ${person}!`);
Expand Down
1 change: 1 addition & 0 deletions files/en-us/web/api/abortsignal/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function myCoolPromiseAPI(/* …, */ { signal }) {
// If the signal is already aborted, immediately throw in order to reject the promise.
if (signal.aborted) {
reject(signal.reason);
return;
}

// Perform the main purpose of the API
Expand Down

0 comments on commit 594eb75

Please sign in to comment.