Skip to content

Add timeout support to ReadSignal.until method#127

Merged
nank1ro merged 5 commits into
mainfrom
copilot/fix-125
Aug 26, 2025
Merged

Add timeout support to ReadSignal.until method#127
nank1ro merged 5 commits into
mainfrom
copilot/fix-125

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 26, 2025

This PR adds an optional timeout parameter to the ReadSignal.until method to prevent memory leaks and provide better control over asynchronous signal waiting.

Background

In issue #124, a user created an extension method that included timeout functionality for ReadSignal, noting that the existing until method was missing timeout support. The library maintainer confirmed this gap and promised to add timeout functionality. The user specifically highlighted that using .timeout() wrapper on the future would result in leaked Effects that never get disposed.

Changes

Core Implementation

Added an optional Duration? timeout parameter to the until method:

FutureOr<T> until(
  bool Function(T value) condition, {
  Duration? timeout,  // New optional parameter
})

The implementation:

  • Maintains full backward compatibility - existing code works unchanged
  • Uses a Timer to complete with TimeoutException when timeout expires
  • Properly disposes both the Effect and Timer to prevent memory leaks
  • Returns immediately when the condition is already met (regardless of timeout)

Usage Examples

// Without timeout (existing behavior)
await signal.until((value) => value > 10);

// With timeout (new feature)  
try {
  final result = await signal.until(
    (value) => value > 10,
    timeout: Duration(seconds: 5),
  );
  print('Condition met: $result');
} catch (TimeoutException) {
  print('Timeout after 5 seconds');
}

Testing

Added comprehensive tests covering:

  • Condition met before timeout
  • Timeout occurs before condition is met
  • Condition already met (immediate return)
  • Proper cleanup on timeout
  • Proper cleanup on success

All 148 tests pass (143 existing + 5 new timeout tests).

Documentation

Updated the API documentation in docs/api-docs/read-signal.mdx to include the new timeout parameter with usage examples.

Benefits

  1. Prevents memory leaks - proper cleanup of Effects and Timers
  2. Better error handling - clear TimeoutException when timeout occurs
  3. Backward compatible - no breaking changes to existing code
  4. Integrated solution - no need for external timeout wrappers that leak resources

Fixes #124.

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:

  • dl-ssl.google.com
    • Triggering command: wget -qO- REDACTED (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 26, 2025

@nank1ro 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying solidart-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9dc1282
Status: ✅  Deploy successful!
Preview URL: https://2f483321.solidart.pages.dev
Branch Preview URL: https://copilot-fix-125.solidart.pages.dev

View logs

Copilot AI and others added 3 commits August 26, 2025 06:21
Co-authored-by: nank1ro <60045235+nank1ro@users.noreply.github.com>
Co-authored-by: nank1ro <60045235+nank1ro@users.noreply.github.com>
Co-authored-by: nank1ro <60045235+nank1ro@users.noreply.github.com>
Copilot AI changed the title [WIP] Add timeout to ReadSignal.until Add timeout support to ReadSignal.until method Aug 26, 2025
Copilot AI requested a review from nank1ro August 26, 2025 06:32
@nank1ro nank1ro marked this pull request as ready for review August 26, 2025 09:10
@nank1ro nank1ro merged commit 7a5af31 into main Aug 26, 2025
1 check failed
@nank1ro nank1ro deleted the copilot/fix-125 branch August 26, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Effect only triggered if another effect exists

2 participants