DEV Community

Cover image for Stop Old Async Results From Updating New State
YeLinAung for dust

Posted on Originally published at dust-codegen.pages.dev

Stop Old Async Results From Updating New State

Manual async loading code beside a Dust runAction example for stale result protection

Flutter state bugs often come from timing.

A user taps refresh twice. The first request finishes last. Now the old result can overwrite the newer state.

Dust State has a small helper for this case.

Use runAction with an action key. Dust keeps the latest token for that key. When an older request finishes, its result is ignored.

The request still runs. Dust does not cancel the network call. It only stops stale success or error handlers from changing state after a newer action has started.

This keeps the ViewModel logic clear. The widget can call one method. The state update stays close to the async work.

Read the Dust stale async actions guide.

Dust #StateManagement #Flutter #Dart #CodeGeneration

Top comments (0)