| 258 | * @since 4.0.0 |
| 259 | */ |
| 260 | export const raceAll = < |
| 261 | const Effects extends NonEmptyReadonlyArray<Effect.Effect<any, any, any>>, |
| 262 | Success extends Schema.Schema<Effect.Success<Effects[number]>>, |
| 263 | Error extends Schema.Schema<Effect.Error<Effects[number]>> |
| 264 | >(options: { |
| 265 | name: string |
| 266 | success: Success |
| 267 | error: Error |
| 268 | effects: Effects |
| 269 | }): Effect.Effect< |
| 270 | Effect.Success<Effects[number]>, |
| 271 | Effect.Error<Effects[number]>, |
| 272 | | Effect.Services<Effects[number]> |
| 273 | | Success["DecodingServices"] |
| 274 | | Success["EncodingServices"] |
| 275 | | Error["DecodingServices"] |
| 276 | | Error["EncodingServices"] |
| 277 | | WorkflowEngine |
| 278 | | WorkflowInstance |
| 279 | > => { |
| 280 | const deferred = make<any, any>(`raceAll/${options.name}`, { |
| 281 | success: options.success, |
| 282 | error: options.error |
| 283 | }) |
| 284 | return Effect.gen(function*() { |
| 285 | const engine = yield* EngineTag |
| 286 | const exit = yield* engine.deferredResult(deferred) |
| 287 | if (Option.isSome(exit)) { |
| 288 | return yield* exit.value |
| 289 | } |
| 290 | return yield* into( |
| 291 | Effect.raceAll(options.effects), |
| 292 | deferred |
| 293 | ) |
| 294 | }) |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Runtime brand identifier for durable deferred tokens. |