Skip to content

Commit

Permalink
revert accidental README change, convert pubsub to SW theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Sergeev committed Jan 30, 2024
1 parent 018abaf commit 1087adb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
30 changes: 15 additions & 15 deletions example/pubsub-data-function.yaml
Original file line number Diff line number Diff line change
@@ -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')
4 changes: 2 additions & 2 deletions src/test/StatedWorkflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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]);

Expand Down

0 comments on commit 1087adb

Please sign in to comment.