-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
ActorHttpInvalidateListenable.ts
41 lines (35 loc) 路 1.13 KB
/
ActorHttpInvalidateListenable.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
import type { IActorTest } from '@comunica/core';
import type {
IActionHttpInvalidate,
IActorHttpInvalidateOutput,
IActorHttpInvalidateArgs,
} from './ActorHttpInvalidate';
import { ActorHttpInvalidate } from './ActorHttpInvalidate';
/**
* An ActorHttpInvalidate actor that allows listeners to be attached.
*
* @see ActorHttpInvalidate
*/
export class ActorHttpInvalidateListenable extends ActorHttpInvalidate {
private readonly invalidateListeners: IInvalidateListener[] = [];
public constructor(args: IActorHttpInvalidateArgs) {
super(args);
this.invalidateListeners = [];
}
public addInvalidateListener(listener: IInvalidateListener): void {
this.invalidateListeners.push(listener);
}
public async test(_action: IActionHttpInvalidate): Promise<IActorTest> {
return true;
}
public async run(action: IActionHttpInvalidate): Promise<IActorHttpInvalidateOutput> {
for (const listener of this.invalidateListeners) {
listener(action);
}
return {};
}
}
/**
* Called when a {@link IActionHttpInvalidate} is received.
*/
export type IInvalidateListener = (action: IActionHttpInvalidate) => void;