Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Task<T, ReqENV, ProvEnv, Err, Async>

Type parameters

  • T

  • ReqENV: Object = {}

  • ProvEnv: Object = {}

  • Err: unknown = Error

  • Async: boolean = false

Hierarchy

  • Task

Index

Accessors

Static empty

  • get empty(): Task<unknown, {}, {}, Error, false>

Methods

access

  • access<E>(): Task<E extends Promise<Z> ? Z : E, E, ProvEnv, Err, E extends Promise<Z> ? true : Async>
  • Required dependencies

    Type parameters

    • E

    Returns Task<E extends Promise<Z> ? Z : E, E, ProvEnv, Err, E extends Promise<Z> ? true : Async>

chain

  • chain<NT, NRE, NPE, NER, A, NA>(fn: (value: T) => Task<NT, NRE, NPE, NER, A>): Task<NT extends Promise<Z> ? Z : NT, ReqENV & NRE, ProvEnv & NPE, NER, NT extends Promise<Z> ? true : NA>
  • Chain another task

    Type parameters

    • NT

    • NRE

    • NPE

    • NER

    • A: boolean

    • NA: boolean = Async extends true ? true : A

    Parameters

    • fn: (value: T) => Task<NT, NRE, NPE, NER, A>
        • (value: T): Task<NT, NRE, NPE, NER, A>
        • Parameters

          • value: T

          Returns Task<NT, NRE, NPE, NER, A>

    Returns Task<NT extends Promise<Z> ? Z : NT, ReqENV & NRE, ProvEnv & NPE, NER, NT extends Promise<Z> ? true : NA>

collectAll

  • collectAll(): Task<T[], ReqENV, ProvEnv, Err, Async>
  • Collect all values to array

    Returns Task<T[], ReqENV, ProvEnv, Err, Async>

collectWhen

  • collectWhen(fn: (item: T) => boolean): Task<T[], ReqENV, ProvEnv, Err, Async>
  • Collect elements with predicate

    Parameters

    • fn: (item: T) => boolean
        • (item: T): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns Task<T[], ReqENV, ProvEnv, Err, Async>

delay

  • delay(time: number): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>
  • delay task on @time ms, change type to async task

    Parameters

    • time: number

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>

ensure

  • ensure(handler: (value: T) => any): Task<T, ReqENV, ProvEnv, Err, Async>
  • Run callback after task finished

    Parameters

    • handler: (value: T) => any
        • (value: T): any
        • Parameters

          • value: T

          Returns any

    Returns Task<T, ReqENV, ProvEnv, Err, Async>

fromCallback

  • fromCallback<T>(fn: (cb: (value: T) => void) => unknown): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : true>
  • Type parameters

    • T

    Parameters

    • fn: (cb: (value: T) => void) => unknown
        • (cb: (value: T) => void): unknown
        • Parameters

          • cb: (value: T) => void
              • (value: T): void
              • Parameters

                • value: T

                Returns void

          Returns unknown

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : true>

map

  • map<R>(fn: (value: T) => R): Task<R extends Promise<Z> ? Z : R, ReqENV, ProvEnv, Err, R extends Promise<Z> ? true : Async>
  • Map task value

    Type parameters

    • R

    Parameters

    • fn: (value: T) => R
        • (value: T): R
        • Parameters

          • value: T

          Returns R

    Returns Task<R extends Promise<Z> ? Z : R, ReqENV, ProvEnv, Err, R extends Promise<Z> ? true : Async>

mapError

  • mapError<NE>(fn: (value: Err) => NE): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, NE, T extends Promise<Z> ? true : Async>
  • Map task error

    Type parameters

    • NE

    Parameters

    • fn: (value: Err) => NE
        • (value: Err): NE
        • Parameters

          • value: Err

          Returns NE

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, NE, T extends Promise<Z> ? true : Async>

mapTo

  • mapTo<R>(value: R): Task<R extends Promise<Z> ? Z : R, ReqENV, ProvEnv, Err, R extends Promise<Z> ? true : Async>
  • Map to value

    Type parameters

    • R

    Parameters

    • value: R

    Returns Task<R extends Promise<Z> ? Z : R, ReqENV, ProvEnv, Err, R extends Promise<Z> ? true : Async>

provide

  • provide<E>(env: E): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv & E, Err, T extends Promise<Z> ? true : Async>
  • Provide dependencies

    Type parameters

    • E: Partial<ReqENV>

    Parameters

    • env: E

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv & E, Err, T extends Promise<Z> ? true : Async>

reduce

  • reduce<R>(fn: (value: T, current: R) => R, initial: R): Task<R extends Promise<Z> ? Z : R, ReqENV, ProvEnv, Err, R extends Promise<Z> ? true : Async>
  • Reduce like native reduce

    Type parameters

    • R

    Parameters

    • fn: (value: T, current: R) => R
        • (value: T, current: R): R
        • Parameters

          • value: T
          • current: R

          Returns R

    • initial: R

    Returns Task<R extends Promise<Z> ? Z : R, ReqENV, ProvEnv, Err, R extends Promise<Z> ? true : Async>

repeat

  • repeat(count: number): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>
  • Repeat next functions @count times

    Parameters

    • count: number

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>

repeatWhile

  • repeatWhile<U>(fn: U): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>
  • Repeat next functions when(condition function)

    Type parameters

    • U: (value: T) => boolean

    Parameters

    • fn: U

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>

retryWhile

  • retryWhile(fn: () => boolean): Task<T, ReqENV, ProvEnv, Err, Async>
  • repeat next functions if task is failed

    Parameters

    • fn: () => boolean
        • (): boolean
        • Returns boolean

    Returns Task<T, ReqENV, ProvEnv, Err, Async>

run

  • run<R>(..._: ProvEnv extends ReqENV ? EmptyArray : [Errors: {[ k in string | number | symbol]: DiffErr<ReqENV, ProvEnv>[k] }]): R
  • Run task, return promise or pure value

    Type parameters

    • R = Async extends true ? Promise<T> : Result<T> | Fail<Err>

    Parameters

    • Rest ..._: ProvEnv extends ReqENV ? EmptyArray : [Errors: {[ k in string | number | symbol]: DiffErr<ReqENV, ProvEnv>[k] }]

    Returns R

runUnsafe

  • runUnsafe<R>(..._: ProvEnv extends ReqENV ? EmptyArray : [Errors: {[ k in string | number | symbol]: DiffErr<ReqENV, ProvEnv>[k] }]): R
  • Run task

    Type parameters

    • R = Async extends true ? Promise<T> : T

    Parameters

    • Rest ..._: ProvEnv extends ReqENV ? EmptyArray : [Errors: {[ k in string | number | symbol]: DiffErr<ReqENV, ProvEnv>[k] }]

    Returns R

structPar

  • structPar<T, R, RENV, PENV, Err, A>(struct: T): Task<R extends Promise<Z> ? Z : R, RENV, PENV, Err, R extends Promise<Z> ? true : A>
  • Type parameters

    • T: Record<string, Task<any, any, {}, Error, false>>

    • R: TaskValue<T>

    • RENV: Object

    • PENV: Object

    • Err: unknown

    • A: boolean

    Parameters

    • struct: T

    Returns Task<R extends Promise<Z> ? Z : R, RENV, PENV, Err, R extends Promise<Z> ? true : A>

tap

  • tap<R>(fn: (value: T) => R): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>
  • Tap like forEach

    Type parameters

    • R

    Parameters

    • fn: (value: T) => R
        • (value: T): R
        • Parameters

          • value: T

          Returns R

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, Err, T extends Promise<Z> ? true : Async>

tapChain

  • tapChain<NT, NRE, NPE, NER, A, NA>(fn: (value: T) => Task<NT, NRE, NPE, NER, A>): Task<T extends Promise<Z> ? Z : T, ReqENV & NRE, ProvEnv & NPE, NER, T extends Promise<Z> ? true : NA>
  • Type parameters

    • NT

    • NRE

    • NPE

    • NER

    • A: boolean

    • NA: boolean = Async extends true ? true : A

    Parameters

    • fn: (value: T) => Task<NT, NRE, NPE, NER, A>
        • (value: T): Task<NT, NRE, NPE, NER, A>
        • Parameters

          • value: T

          Returns Task<NT, NRE, NPE, NER, A>

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV & NRE, ProvEnv & NPE, NER, T extends Promise<Z> ? true : NA>

timeout

  • timeout(max: number): Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, TimeOutError | Err, T extends Promise<Z> ? true : Async>
  • Parameters

    • max: number

    Returns Task<T extends Promise<Z> ? Z : T, ReqENV, ProvEnv, TimeOutError | Err, T extends Promise<Z> ? true : Async>

Static fail

  • fail<ERR>(err: ERR): Task<Error, {}, {}, ERR, false>
  • Create failed task from any value

    Type parameters

    • ERR

    Parameters

    • err: ERR

    Returns Task<Error, {}, {}, ERR, false>

Static fromCallback

  • fromCallback<T>(fn: (cb: (value: T) => void) => unknown): Task<T extends Promise<Z> ? Z : T, {}, {}, Error, T extends Promise<Z> ? true : true>
  • Type parameters

    • T

    Parameters

    • fn: (cb: (value: T) => void) => unknown
        • (cb: (value: T) => void): unknown
        • Parameters

          • cb: (value: T) => void
              • (value: T): void
              • Parameters

                • value: T

                Returns void

          Returns unknown

    Returns Task<T extends Promise<Z> ? Z : T, {}, {}, Error, T extends Promise<Z> ? true : true>

Static sequenceFromIterable

  • sequenceFromIterable<R>(itererable: Iterable<R> | AsyncIterable<R>): Task<R extends Promise<Z> ? Z : R, {}, {}, Error, R extends Promise<Z> ? true : false>
  • Create succeed task from iterable

    Type parameters

    • R

    Parameters

    • itererable: Iterable<R> | AsyncIterable<R>

    Returns Task<R extends Promise<Z> ? Z : R, {}, {}, Error, R extends Promise<Z> ? true : false>

Static sequenceFromObject

  • sequenceFromObject<T, R>(obj: T): Task<R extends Promise<Z> ? Z : R, {}, {}, Error, R extends Promise<Z> ? true : false>
  • Type parameters

    • T: Object

    • R: [keyof T, T[keyof T]]

    Parameters

    • obj: T

    Returns Task<R extends Promise<Z> ? Z : R, {}, {}, Error, R extends Promise<Z> ? true : false>

Static sequenceGen

  • sequenceGen<T>(fn: () => Generator<T, void, unknown> | AsyncGenerator<T, void, unknown>): Task<T extends Promise<Z> ? Z : T, {}, {}, Error, T extends Promise<Z> ? true : false>
  • Create succeed task from Generator

    Type parameters

    • T

    Parameters

    • fn: () => Generator<T, void, unknown> | AsyncGenerator<T, void, unknown>
        • (): Generator<T, void, unknown> | AsyncGenerator<T, void, unknown>
        • Returns Generator<T, void, unknown> | AsyncGenerator<T, void, unknown>

    Returns Task<T extends Promise<Z> ? Z : T, {}, {}, Error, T extends Promise<Z> ? true : false>

Static struct

  • struct<T, R, RENV, PENV, Err, A>(struct: T): Task<TaskValue<T> extends Promise<Z> ? Z : TaskValue<T>, TaskReqEnv<T>, TaskProvEnv<T>, TaskError<T>, TaskValue<T> extends Promise<Z> ? true : TaskAsync<T>>
  • Create succeed task from object with task

    Type parameters

    • T: Record<string, Task<any, any, {}, Error, false>>

    • R: TaskValue<T>

    • RENV: Object

    • PENV: Object

    • Err: unknown

    • A: boolean

    Parameters

    • struct: T

    Returns Task<TaskValue<T> extends Promise<Z> ? Z : TaskValue<T>, TaskReqEnv<T>, TaskProvEnv<T>, TaskError<T>, TaskValue<T> extends Promise<Z> ? true : TaskAsync<T>>

Static structPar

  • structPar<T, R, RENV, PENV, Err, A>(struct: T): Task<TaskValue<T> extends Promise<Z> ? Z : TaskValue<T>, TaskReqEnv<T>, TaskProvEnv<T>, TaskError<T>, TaskValue<T> extends Promise<Z> ? true : TaskAsync<T>>
  • Create succeed task from object with task, runs parallel

    Type parameters

    • T: Record<string, Task<any, any, {}, Error, false>>

    • R: TaskValue<T>

    • RENV: Object

    • PENV: Object

    • Err: unknown

    • A: boolean

    Parameters

    • struct: T

    Returns Task<TaskValue<T> extends Promise<Z> ? Z : TaskValue<T>, TaskReqEnv<T>, TaskProvEnv<T>, TaskError<T>, TaskValue<T> extends Promise<Z> ? true : TaskAsync<T>>

Static succeed

  • succeed<T>(value: T): Task<T extends Promise<Z> ? Z : T, {}, {}, Error, T extends Promise<Z> ? true : false>
  • Create succeed task from any value

    Type parameters

    • T

    Parameters

    • value: T

    Returns Task<T extends Promise<Z> ? Z : T, {}, {}, Error, T extends Promise<Z> ? true : false>

Generated using TypeDoc