Skip to content

Commit

Permalink
Add temprary batching example
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Nov 19, 2024
1 parent 1929633 commit 693abe2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ int main(int argc, char **argv) {
// Publish data
printf("Press CTRL-C to quit...\n");
char buf[256];
zp_batch_start(z_loan(s));
for (int idx = 0; idx < n; ++idx) {
z_sleep_s(1);
sprintf(buf, "[%4d] %s", idx, value);
Expand All @@ -117,7 +118,14 @@ int main(int argc, char **argv) {
z_bytes_copy_from_str(&payload, buf);

z_publisher_put(z_loan(pub), z_move(payload), NULL);

if (idx % 3 == 0) {
printf("FLush data\n");
zp_batch_stop(z_loan(s));
zp_batch_start(z_loan(s));
}
}
zp_batch_stop(z_loan(s));
// Clean up
z_drop(z_move(pub));
z_drop(z_move(s));
Expand Down

0 comments on commit 693abe2

Please sign in to comment.