forked from i-am-bee/bee-agent-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
piping.ts
32 lines (25 loc) · 817 Bytes
/
piping.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
import { Emitter, EventMeta } from "bee-agent-framework/emitter/emitter";
const first = new Emitter({
namespace: ["app"],
});
first.match("*.*", (data: unknown, event: EventMeta) => {
console.log(
`'first' has retrieved the following event ${event.path}, isDirect: ${event.source === first}`,
);
});
const second = new Emitter({
namespace: ["app", "llm"],
});
second.match("*.*", (data: unknown, event: EventMeta) => {
console.log(
`'second' has retrieved the following event '${event.path}', isDirect: ${event.source === second}`,
);
});
// Propagate all events from the 'second' emitter to the 'first' emitter
const unpipe = second.pipe(first);
await first.emit("a", {});
await second.emit("b", {});
console.log("Unpipe");
unpipe();
await first.emit("c", {});
await second.emit("d", {});