diff --git a/packages/foundation/example/pingback/server-two.ts b/packages/foundation/example/pingback/server-two.ts index b3830b0d..e5fe72fa 100644 --- a/packages/foundation/example/pingback/server-two.ts +++ b/packages/foundation/example/pingback/server-two.ts @@ -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, @@ -67,14 +67,14 @@ export function simulation(): FoundationSimulator { // ); // 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( // { @@ -86,7 +86,7 @@ export function simulation(): FoundationSimulator { // ); yield* put(bappedTrigger()); } - } + }); } return { diff --git a/packages/foundation/tests/webhook.test.ts b/packages/foundation/tests/webhook.test.ts index 855276ac..8c490052 100644 --- a/packages/foundation/tests/webhook.test.ts +++ b/packages/foundation/tests/webhook.test.ts @@ -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 @@ -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 }); });