Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/foundation/example/pingback/server-two.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { put, take, takeEvery, type Action } from "starfx";
import { put, takeEvery, type Action } from "starfx";
import { createFoundationSimulationServer } from "../../src/index.ts";
import type {
ExtendSimulationSchema,
Expand Down Expand Up @@ -67,14 +67,14 @@ export function simulation(): FoundationSimulator<any> {
// );
// to avoid the double call from the two watchers
// skip this one
// yield* put(bappedTrigger());
yield* put(bappedTrigger());
}
});
}
// using take and your own iteration loop is another method of doing of listening for events
function* boopWatcherOptionTwo() {
while (true) {
const action = yield* take("*");
// this `*` will match all actions and you can filter inside
yield* takeEvery("*", function* (action) {
if (isBoopEvent(action)) {
// console.dir(
// {
Expand All @@ -86,7 +86,7 @@ export function simulation(): FoundationSimulator<any> {
// );
yield* put(bappedTrigger());
}
}
});
}

return {
Expand Down
6 changes: 3 additions & 3 deletions packages/foundation/tests/webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe("pingback", () => {
// check the webhook listener is gets double incremented
let r7 = await f(`${urlOne}/get/bap`);
// note that we have two watchers
// but only one sends the increment request
expect(r7).toEqual({ count: 1 });
// and each webhook event triggers both watchers
expect(r7).toEqual({ count: 2 });

// trigger via external endpoint on one
// which will webhook to the other
Expand All @@ -68,6 +68,6 @@ describe("pingback", () => {

// our watcher has updated the bapped count though
let r11 = await f(`${urlOne}/get/bap`);
expect(r11).toEqual({ count: 2 }); // ie see r9 vs r11
expect(r11).toEqual({ count: 4 }); // ie see r9 vs r11
});
});
Loading