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:

  1. A call to a function fetchUsers which returns a Future
  2. 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

Constructors

Race(Map effects, {RaceResult? result})
Creates an instance of a Race effect.

Properties

effects Map
Effects to Race
final
hashCode int
The hash code for this object.
no setterinherited
result Result?
Result after effect is resolved.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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