zibri
    Preparing search index...

    Definition for a service that handles multithreading.

    interface MultithreadingServiceInterface {
        init: () => void | Promise<void>;
        queueThreadJob: <WorkerData extends BaseThreadJobWorkerData>(
            threadJobData: ThreadJobData<WorkerData>,
        ) => string | Promise<string>;
        requeueThreadJob: (
            jobId: string,
            data?: ThreadJobDataFunctions,
        ) => void | Promise<void>;
        rerunThreadJob: <WorkerData extends BaseThreadJobWorkerData, ResultType>(
            jobId: string,
            data?: ThreadJobDataFunctions,
        ) =>
            | ThreadJobEntity<WorkerData, ResultType>
            | Promise<ThreadJobEntity<WorkerData, ResultType>>;
        run: <InputType, ResultType>(
            func: ThreadJobFunction<InputType, ResultType>,
            input: InputType,
            timeout?: number,
            priority?: boolean,
        ) => ResultType | Promise<ResultType>;
        runThreadJob: <WorkerData extends BaseThreadJobWorkerData, ResultType>(
            threadJobData: ThreadJobData<WorkerData>,
        ) =>
            | ThreadJobEntity<WorkerData, ResultType>
            | Promise<ThreadJobEntity<WorkerData, ResultType>>;
        shutdown: () => void | Promise<void>;
        waitForThreadJob: <
            ResultType,
            WorkerData extends BaseThreadJobWorkerData = BaseThreadJobWorkerData,
        >(
            jobId: string,
        ) =>
            | ThreadJobEntity<WorkerData, ResultType>
            | Promise<ThreadJobEntity<WorkerData, ResultType>>;
    }

    Implemented by

    Index

    Properties

    init: () => void | Promise<void>

    Initializes the service.

    queueThreadJob: <WorkerData extends BaseThreadJobWorkerData>(
        threadJobData: ThreadJobData<WorkerData>,
    ) => string | Promise<string>

    Creates and queues a thread job with the given data.

    Type Declaration

      • <WorkerData extends BaseThreadJobWorkerData>(
            threadJobData: ThreadJobData<WorkerData>,
        ): string | Promise<string>
      • Type Parameters

        Parameters

        • threadJobData: ThreadJobData<WorkerData>

          The data to create the thread job from.

        Returns string | Promise<string>

        The id of the created thread job in the data source and queue.

        This differs from the threadId, which is created by the os and set when the thread actually starts..

    requeueThreadJob: (
        jobId: string,
        data?: ThreadJobDataFunctions,
    ) => void | Promise<void>

    Requeues a thread job that was already completed.

    Type Declaration

    rerunThreadJob: <WorkerData extends BaseThreadJobWorkerData, ResultType>(
        jobId: string,
        data?: ThreadJobDataFunctions,
    ) =>
        | ThreadJobEntity<WorkerData, ResultType>
        | Promise<ThreadJobEntity<WorkerData, ResultType>>

    Reruns a thread job that was already completed.

    Type Declaration

    run: <InputType, ResultType>(
        func: ThreadJobFunction<InputType, ResultType>,
        input: InputType,
        timeout?: number,
        priority?: boolean,
    ) => ResultType | Promise<ResultType>

    Runs the given function on a separate thread. This will not persist the state in the data source.

    IMPORTANT: This uses "eval" in the thread worker, so make sure that the data passed is not malicious.

    Type Declaration

      • <InputType, ResultType>(
            func: ThreadJobFunction<InputType, ResultType>,
            input: InputType,
            timeout?: number,
            priority?: boolean,
        ): ResultType | Promise<ResultType>
      • Type Parameters

        • InputType
        • ResultType

        Parameters

        • func: ThreadJobFunction<InputType, ResultType>

          The function that should be run in a separate thread.

        • input: InputType

          The input value of the function.

        • Optionaltimeout: number

          A custom timeout for the task. Defaults to 5 minutes or an hour, depending on the priority.

        • Optionalpriority: boolean

          Whether or not the function should make use of priority workers or not. Defaults to true.

        Returns ResultType | Promise<ResultType>

        The result value of the function passed.

    When either the function itself throws an error or something didn't work during parsing/evaluation.

    runThreadJob: <WorkerData extends BaseThreadJobWorkerData, ResultType>(
        threadJobData: ThreadJobData<WorkerData>,
    ) =>
        | ThreadJobEntity<WorkerData, ResultType>
        | Promise<ThreadJobEntity<WorkerData, ResultType>>

    Queues a thread job for the given data and waits for its completion.

    Type Declaration

    shutdown: () => void | Promise<void>

    Terminates all the workers.

    waitForThreadJob: <
        ResultType,
        WorkerData extends BaseThreadJobWorkerData = BaseThreadJobWorkerData,
    >(
        jobId: string,
    ) =>
        | ThreadJobEntity<WorkerData, ResultType>
        | Promise<ThreadJobEntity<WorkerData, ResultType>>

    Waits for the thread job with the given id to complete.

    Type Declaration