Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Brings cancellable async utilities from VS Code core (src/vs/base/common/async.ts) to improve async operation control and cancellation support.

Added APIs

  • CancelablePromise<T> - Promise interface with .cancel() method
  • CancellationError - Dedicated error class for cancellation scenarios
  • createCancelablePromise<T>(callback) - Create promises cancellable via token or .cancel()
  • timeout(millis) / timeout(millis, token) - Enhanced with cancellation support (backward compatible)
  • raceCancellation<T>(promise, token, defaultValue?) - Race promise vs cancellation, resolves gracefully
  • raceCancellationError<T>(promise, token) - Race promise vs cancellation, rejects with CancellationError

Usage

// Imperative cancellation
const t = timeout(1000);
t.cancel();

// Token-based cancellation  
await timeout(1000, cancellationToken);

// Race with graceful fallback
const result = await raceCancellation(operation, token, 'default');

// Race with error on cancel
await raceCancellationError(operation, token);

// Custom cancellable operations
const promise = createCancelablePromise(async (token) => {
    await longOperation(token);
    return result;
});
promise.cancel();

Existing timeout() calls remain unchanged. 23 unit tests added covering all new functionality.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/microsoft/vscode-python-environments/pulls/952/comments
    • Triggering command: curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Bring cancellable async timeout from core</issue_title>
<issue_description>From: #952 (comment)

Core has lots of useful functions like: https://github.com/microsoft/vscode/blob/2ca79c442ac3813c1531b8fea152299f64f012c7/src/vs/base/common/async.ts#L534

We should bring them too in this repo. </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add cancellable async timeout from core Add cancellable async timeout utilities from VS Code core Nov 11, 2025
Copilot finished work on behalf of eleanorjboyd November 11, 2025 21:55
Copilot AI requested a review from eleanorjboyd November 11, 2025 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring cancellable async timeout from core

2 participants