// Creating a self-destruct sequence (that we can cancel!)
const controller = new AbortController();

async function selfDestruct() {
try {
for(let i = 10; i > 0; i--) {
controller.signal.throwIfAborted();
print(`Self-destruct in ${i}...`);
await sleep(1000);
}
print("💥 BOOM!");
} catch (e) {
print("Self-destruct cancelled! Phew!");
}
}

// Start the countdown
selfDestruct();

// Changed our mind? Just abort!
controller.abort("Never mind!");

Common Use Cases:

  • Cancelling long-running network requests
  • Implementing timeout mechanisms
  • Stopping turtle operations mid-way
  • Cancelling resource-intensive computations

This implementation closely follows the web standard but is adapted for ComputerCraft's environment. Some subtle differences may exist.

Classes

AbortController
AbortSignal