Bird
0
0

How can you combine AbortController with a Promise to reject it when aborted?

hard📝 Application Q9 of 15
Node.js - Timers and Scheduling
How can you combine AbortController with a Promise to reject it when aborted?
ACall abort() inside Promise executor to reject it
BUse signal.aborted as Promise resolve value
CPass abort() as Promise reject callback
DCreate AbortController, then listen to signal 'abort' event to reject the Promise
Step-by-Step Solution
Solution:
  1. Step 1: Setup AbortController and Promise

    Create controller and a Promise that listens to the signal's 'abort' event.
  2. Step 2: Reject Promise on abort event

    Inside the event listener, call the Promise's reject function to cancel the operation.
  3. Final Answer:

    Create AbortController, then listen to signal 'abort' event to reject the Promise -> Option D
  4. Quick Check:

    Use abort event to reject Promise [OK]
Quick Trick: Reject Promise inside abort event listener [OK]
Common Mistakes:
  • Calling abort() inside Promise executor
  • Passing abort() as reject callback
  • Using aborted boolean as resolve value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes