UNPKG

2.56 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Observable, Observer } from 'rxjs';
9import { BaseException } from '../../exception/index';
10import { JsonValue } from '../../json/index';
11import { LoggerApi } from '../../logger';
12import { JobDescription, JobHandler, JobHandlerContext } from './api';
13export declare class ChannelAlreadyExistException extends BaseException {
14 constructor(name: string);
15}
16/**
17 * Interface for the JobHandler context that is used when using `createJobHandler()`. It extends
18 * the basic `JobHandlerContext` with additional functionality.
19 */
20export interface SimpleJobHandlerContext<A extends JsonValue, I extends JsonValue, O extends JsonValue> extends JobHandlerContext<A, I, O> {
21 createChannel: (name: string) => Observer<JsonValue>;
22 input: Observable<I>;
23}
24/**
25 * A simple version of the JobHandler. This simplifies a lot of the interaction with the job
26 * scheduler and registry. For example, instead of returning a JobOutboundMessage observable, you
27 * can directly return an output.
28 */
29export declare type SimpleJobHandlerFn<A extends JsonValue, I extends JsonValue, O extends JsonValue> = (input: A, context: SimpleJobHandlerContext<A, I, O>) => O | Promise<O> | Observable<O>;
30/**
31 * Make a simple job handler that sets start and end from a function that's synchronous.
32 *
33 * @param fn The function to create a handler for.
34 * @param options An optional set of properties to set on the handler. Some fields might be
35 * required by registry or schedulers.
36 */
37export declare function createJobHandler<A extends JsonValue, I extends JsonValue, O extends JsonValue>(fn: SimpleJobHandlerFn<A, I, O>, options?: Partial<JobDescription>): JobHandler<A, I, O>;
38/**
39 * Lazily create a job using a function.
40 * @param loader A factory function that returns a promise/observable of a JobHandler.
41 * @param options Same options as createJob.
42 */
43export declare function createJobFactory<A extends JsonValue, I extends JsonValue, O extends JsonValue>(loader: () => Promise<JobHandler<A, I, O>>, options?: Partial<JobDescription>): JobHandler<A, I, O>;
44/**
45 * Creates a job that logs out input/output messages of another Job. The messages are still
46 * propagated to the other job.
47 */
48export declare function createLoggerJob<A extends JsonValue, I extends JsonValue, O extends JsonValue>(job: JobHandler<A, I, O>, logger: LoggerApi): JobHandler<A, I, O>;