-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathdispatcher_spec.ts
42 lines (37 loc) · 1.37 KB
/
dispatcher_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { JsonValue } from '@angular-devkit/core';
import { lastValueFrom } from 'rxjs';
import { JobHandler } from './api';
import { createJobHandler } from './create-job-handler';
import { createDispatcher } from './dispatcher';
import { SimpleJobRegistry } from './simple-registry';
import { SimpleScheduler } from './simple-scheduler';
describe('createDispatcher', () => {
it('works', async () => {
const registry = new SimpleJobRegistry();
const scheduler = new SimpleScheduler(registry);
const dispatcher = createDispatcher({
name: 'add',
argument: { items: { type: 'number' } },
output: { type: 'number' },
});
const add0 = createJobHandler((input: number[]) => input.reduce((a, c) => a + c, 0), {
name: 'add0',
});
const add100 = createJobHandler((input: number[]) => input.reduce((a, c) => a + c, 100), {
name: 'add100',
});
registry.register(dispatcher);
registry.register(add0);
registry.register(add100);
dispatcher.setDefaultJob(add0 as JobHandler<JsonValue, JsonValue, number>);
const sum = scheduler.schedule('add', [1, 2, 3, 4]);
expect(await lastValueFrom(sum.output)).toBe(10);
});
});