TaskRegistry
in package
FinalYes
中止できるバックグラウンド処理の登録簿
処理の種類(進捗表示の type と同じ文字列)ごとに、中止要求の置き場所と中止してよい権限を持つ。 中止ボタンは処理の種類だけを送り、権限の判定と中止要求はここに登録した内容で行う。 拡張アプリが独自のバックグラウンド処理を中止できるようにするには、ServiceProvider::init() で Application::make('background-task.registry') に register() する。
Table of Contents
Properties
- $definitions : array<string, array{authorizer: callable, flagFactory: callable|null, runningChecker: callable|null}>
- $flagDirectory : string
- $tokens : array<string, CancellationToken>
Methods
- __construct() : mixed
- has() : bool
- isAuthorized() : bool
- isRunning() : bool
- register() : void
- token() : CancellationToken
- 同じ種類には同じインスタンスを返す。開始処理と実処理で別々に取り出しても、begin() した実行 ID を引き継ぐため
Properties
$definitions
private
array<string, array{authorizer: callable, flagFactory: callable|null, runningChecker: callable|null}>
$definitions
= []
$flagDirectory
private
string
$flagDirectory
$tokens
private
array<string, CancellationToken>
$tokens
= []
Methods
__construct()
public
__construct(string $flagDirectory) : mixed
Parameters
- $flagDirectory : string
-
中止要求の置き場所を指定しない処理のフラグを置くディレクトリ
has()
public
has(string $type) : bool
Parameters
- $type : string
Return values
boolisAuthorized()
public
isAuthorized(string $type) : bool
Parameters
- $type : string
Return values
boolisRunning()
public
isRunning(string $type) : bool
Parameters
- $type : string
Return values
boolregister()
public
register(string $type, callable(CancellationToken): bool $authorizer[, callable(): TerminateFlag|null $flagFactory = null ][, callable(): bool|null $runningChecker = null ]) : void
Parameters
- $type : string
-
処理の種類
- $authorizer : callable(CancellationToken): bool
-
現在のユーザーが中止してよいか。開始できる権限と揃え、 全ブログ共通のロックで動く処理は $token->isStartedBy((string) BID) で開始したブログとも照合する
- $flagFactory : callable(): TerminateFlag|null = null
-
既存のフラグを共有する場合に指定する
- $runningChecker : callable(): bool|null = null
-
実行中か(ロック保持中か等)。指定すると、実行中でないときの 中止要求を受け付けない(終わった処理に中止要求だけが残らないようにする)
token()
同じ種類には同じインスタンスを返す。開始処理と実処理で別々に取り出しても、begin() した実行 ID を引き継ぐため
public
token(string $type) : CancellationToken
Parameters
- $type : string