diff --git a/README.md b/README.md index 0582d78..3bac691 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,7 @@ runParallel(template, 10) let's modify our homeworlds example to make a concurrent homeworlds example. We have used the stated `!` operator to remove `personDetails` and `homeworldDetails` from the output to avoid clutter. JSONata automatically makes array -```json +```json > .init -f "example/concurrent-homeworlds.json" { "people": [ diff --git a/example/pubsub-data-function.yaml b/example/pubsub-data-function.yaml index 6f1cb9a..48aac52 100644 --- a/example/pubsub-data-function.yaml +++ b/example/pubsub-data-function.yaml @@ -1,25 +1,25 @@ -# producer will be sending data function output to the "type" topic +# Droid R2-D2 is sending messages to the Rebel Alliance's communication channel produceParams: - type: "my-topic" - data: "${ function(){ {'msg': 'hello', 'rando': $random()} } }" + type: "rebel-comm-channel" + data: "${ function(){ {'message': 'Rebel Fleet Coordinates', 'location': $random()} } }" client: type: test -# producer will be invoking "to" function for each consumed event -subscribeParams: #parameters for subscribing to a cloud event +# Droid C-3PO will intercept and log each received message for the Rebel Alliance +subscribeParams: #parameters for subscribing to a holocomm transmission source: cloudEvent - type: /${ produceParams.type } # subscribe to the same topic as we are publishing to test events + type: /${ produceParams.type } # subscribe to the same channel as R2-D2 to intercept messages to: /${ function($e){( - $set('/rxLog', rxLog~>$append($e)); + $set('/interceptedMessages', interceptedMessages~>$append($e)); )} } - subscriberId: dingus + subscriberId: protocolDroid initialPosition: latest client: - type: test -# starts producer function + type: test +# Activates R2-D2's message transmission function every 50 milliseconds send: "${ $setInterval( function(){ $publish(produceParams)}, 50) }" -# starts consumer function +# Activates C-3PO's message interception function recv$: $subscribe(subscribeParams) -# rxLog is a field of the template where the consumer function will be storing results of event processing -rxLog: [ ] -# this is a condition that will stop the workflow when rxLog has 5 elements -stop$: ($count(rxLog)=10?($clearInterval(send);'done'):'still going') +# interceptedMessages is where C-3PO will store the results of message decoding +interceptedMessages: [ ] +# This condition stops the operation when interceptedMessages has 10 elements +stop$: ($count(interceptedMessages)>=10?($clearInterval(send);'missionAccomplished'):'operationOngoing') diff --git a/src/test/StatedWorkflow.test.js b/src/test/StatedWorkflow.test.js index c2a1ef3..a87795a 100644 --- a/src/test/StatedWorkflow.test.js +++ b/src/test/StatedWorkflow.test.js @@ -747,7 +747,7 @@ test("Template Data Change Callback with rate limit", async () => { const counts = []; const dataChangeCallback = rateLimit(async (output, theseThatChanged) => { - counts.push(output.rxLog.length); + counts.push(output.interceptedMessages.length); }, 1000); tp.setDataChangeCallback('/', dataChangeCallback); @@ -760,7 +760,7 @@ test("Template Data Change Callback with rate limit", async () => { } // Assertions - expect(tp.output.stop$).toEqual('done'); + expect(tp.output.stop$).toEqual('missionAccomplished'); // Assert that the data change callback was called twice, with the first and the last events only expect(counts).toEqual([0,10]);