riverpod-cancel

Cancel Riverpod async requests with ref.onDispose and debounce via auto-dispose providers.

Updated Mar 28, 2026
One-click install
npx skills add https://github.com/masssi164/weave --skill riverpod-cancel-masssi164
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: riverpod-cancel
Source: https://github.com/masssi164/weave/tree/main/.agent/skills/riverpod-cancel
Command: npx skills add https://github.com/masssi164/weave --skill riverpod-cancel-masssi164

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Riverpod async requests can leak when a user navigates away or triggers rapid refreshes; this skill provides patterns to cancel in-flight requests automatically using ref.onDispose and to debounce repeated triggers to avoid redundant work.

Core Features & Use Cases

  • Automatic cancellation on dispose: Attach onDispose to streams or HTTP clients to abort in-flight requests when the page is left.
  • Debounced refreshes: Introduce a delay before issuing requests to coalesce rapid user actions.
  • Guidance for implementation: Provides concrete code patterns and extension ideas for integrating with Riverpod providers.

Quick Start

Create an auto-dispose provider, instantiate your HTTP client inside it, and register ref.onDispose to close the client when the provider is disposed.

Frequently Asked Questions about riverpod-cancel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cancel in-flight Riverpod async requests when a user navigates away?

To cancel in-flight Riverpod async requests, use auto-dispose providers and register ref.onDispose to close the HTTP client created inside the provider. This automatically aborts pending calls when the user leaves the page.

What's the best way to debounce rapid refreshes in Flutter Riverpod?

The best way to debounce rapid refreshes in Flutter Riverpod is to introduce a delay before issuing requests, coalescing redundant triggers. This prevents unnecessary work when users trigger rapid updates.

Why do my Riverpod HTTP clients leak during page navigation?

Riverpod HTTP clients leak because they are not properly disposed when navigating away. To fix this, instantiate the HTTP client inside an auto-dispose provider and register ref.onDispose to close it.

Do I need auto-dispose providers to clean up Riverpod streams?

Yes, auto-dispose providers are required for resource cleanup in Riverpod. They enable the ref.onDispose callback, which closes HTTP clients or cancels streams automatically when the provider is no longer needed.

Can I implement resource cleanup and debouncing together in Riverpod?

You can implement resource cleanup and debouncing together in Riverpod by combining ref.onDispose for client closure with a delay mechanism to coalesce rapid user actions, ensuring efficient async request handling.