Module utils/abortController

🎮 A TypeScript implementation of the standard AbortController API for ComputerCraft! Perfect for when you need to cancel operations faster than a creeper changes its mind.

Key Features:

  • 🛑 Cancel async operations gracefully
  • ⏲️ Set timeouts that actually work
  • 🔗 Combine multiple abort signals
  • 🎯 Event-based cancellation handling
// 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