FutureContext class
非同期(Async)状態を管理する. FutureContextの目標はキャンセル可能な非同期処理のサポートである.
処理終了後、必ずしも close をコールする必要はない(メモリリークはしない)が、 設計上は close をコールすることを推奨する.
開発者はFutureContext.suspend()に関数を渡し、実行を行う. suspend()は実行前後にFutureContextの状態を確認し、必要であればキャンセル等の処理や中断を行う.
NOTE. 2021-05 Flutter 2.2(Dart 2.12)現在、言語仕様としてKotlinのSuspend関数のような状態管理を行えない. そのため、開発者側で適度にブロックを区切って実行を行えるようサポートする.
KotlinにはCoroutineDispatcherのようなさらに上位(周辺)の仕組みがあるが、 目的に対してオーバースペックであるため実装を見送る.
処理が冗長になることと、Dart標準からかけ離れていくリスクがあるため、 使用箇所については慎重に検討が必要.
Constructors
- FutureContext({String? tag, int debugCallStackLevel = 0})
- 空のFutureContextを作成する.
- FutureContext.child(FutureContext parent, {String? tag, int debugCallStackLevel = 0})
- 指定した親Contextを持つFutureContextを作成する.
-
FutureContext.group(Iterable<
FutureContext> group, {String? tag, int debugCallStackLevel = 0}) - 指定した複数の親Contextを持つFutureContextを作成する.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isActive → bool
-
処理が継続中の場合trueを返却する.
no setter
- isCanceled → bool
-
処理がキャンセル済みの場合true.
no setter
-
isCanceledStream
→ Stream<
bool> -
キャンセル状態をハンドリングするStreamを返却する.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tag → String?
-
キャンセル識別用タグ
final
Methods
-
close(
) → Future - Futureをキャンセルする. すでにキャンセル済みの場合は何もしない.
-
delayed(
Duration duration) → Future - 指定時間Contextを停止させる. delayed()の最中にキャンセルが発生した場合、速やかにContext処理は停止する.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
suspend<
T2> (FutureSuspendBlock< T2> block) → Future<T2> - 非同期処理の特定1ブロックを実行する. これはFutureContext
-
toString(
) → String -
A string representation of this object.
override
-
withTimeout<
T2> (Duration timeout, FutureSuspendBlock< T2> block, {int? debugCallStackLevel}) → Future<T2> - タイムアウト付きの非同期処理を開始する.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited