| 359 | * An effected program. |
| 360 | */ |
| 361 | export class Effected<out E extends Effect, out R> implements Iterable<E, R, unknown> { |
| 362 | declare public readonly [Symbol.iterator]: () => Iterator<E, R, unknown>; |
| 363 | |
| 364 | declare public readonly runSync: [ExtractUnhandled<E>] extends [never] ? |
| 365 | () => ExtractDefaultTerminateType<E> | R |
| 366 | : UnhandledEffect<ExtractUnhandled<E>>; |
| 367 | declare public readonly runAsync: [ExtractUnhandled<E>] extends [never] ? |
| 368 | () => Promise<ExtractDefaultTerminateType<E> | R> |
| 369 | : UnhandledEffect<ExtractUnhandled<E>>; |
| 370 | declare public readonly runSyncUnsafe: () => ExtractDefaultTerminateType<E> | R; |
| 371 | declare public readonly runAsyncUnsafe: () => Promise<ExtractDefaultTerminateType<E> | R>; |
| 372 | |
| 373 | private constructor(fn: () => Iterator<E, R, unknown>, magicWords?: string) { |
| 374 | if (magicWords !== "Yes, I’m sure I want to call the constructor of Effected directly.") |
| 375 | logger.warn( |
| 376 | "You should not call the constructor of `Effected` directly. Use `effected` instead.", |
| 377 | ); |
| 378 | |
| 379 | this[Symbol.iterator] = fn; |
| 380 | |
| 381 | this.runSync = (() => runSync(this as never)) as never; |
| 382 | this.runAsync = (() => runAsync(this as never)) as never; |
| 383 | this.runSyncUnsafe = () => runSync(this as never); |
| 384 | this.runAsyncUnsafe = () => runAsync(this as never); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Create an {@link Effected} instance that just returns the value. |
| 389 | * @param value The value to return. |
| 390 | * @returns |
| 391 | * |
| 392 | * @since 0.1.2 |
| 393 | */ |
| 394 | static of<R>(value: R): Effected<never, R> { |
| 395 | return effected(() => ({ next: () => ({ done: true, value }) })) as Effected<never, R>; |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Create an {@link Effected} instance that just returns the value from a getter. |
| 400 | * @param getter The getter to get the value. |
| 401 | * @returns |
| 402 | */ |
| 403 | static from<R>(getter: () => R): Effected<never, R> { |
| 404 | return effected(() => ({ next: () => ({ done: true, value: getter() }) })) as Effected< |
| 405 | never, |
| 406 | R |
| 407 | >; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Combine multiple effected programs into one, running them in parallel and produces a tuple or |
| 412 | * object with the results. |
| 413 | * @param effects An iterable of effected programs or an object with effected programs as values. |
| 414 | * @returns |
| 415 | * |
| 416 | * @see {@linkcode Effected.allSeq} for the sequential version. |
| 417 | * |
| 418 | * @since 0.3.2 |
nothing calls this directly
no outgoing calls
no test coverage detected