Race class
Creates an Effect description that instructs the middleware to run a Race between multiple Effects.
effects is a dictionary of the form {label: effect, ...}
Example
The following example runs a race between two effects:
- A call to a function
fetchUsers
which returns a Future - A
CancelFetch
action which may be eventually dispatched on the Store
import 'package:redux_saga/redux_saga.dart';
import 'fetchUsers.dart';
//...
fetchUsersSaga() sync* {
var result = RaceResult();
yield Race({
#response: Call(fetchUsers),
#cancel: Take(pattern: CancelFetch),
}, result: result);
//result.key is winner effect
//result.keyValue is winner effects result
}
Race effects result is a RaceResult which has a dictionary value with a single entry basically.
Single result value can be accessed through result.key
and result.keyValue
easily.
If Call(fetchUsers)
resolves (or rejects) first, the result of Race
will be an object
with a single keyed object {response: result}
where result
is the resolved result of fetchUsers
.
If an action of type CancelFetch
is dispatched on the Store before fetchUsers
completes, the result
will be a single keyed object {cancel: action}
, where action is the dispatched action.
Notes
When resolving a Race
, the middleware automatically cancels all the losing Effects.
- Inheritance
-
- Object
- Effect
- EffectWithResult
- Race
Constructors
- Race(Map effects, {RaceResult? result})
- Creates an instance of a Race effect.
Properties
Methods
-
getDefinition(
) → Map< String, dynamic> -
Returns all properties of effect as a dictionary object
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited