examples/

directory
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT

README

Examples

Runnable parsec examples. Every example is a standalone main package with its own README.md. Compile and run them with go run:

go run ./examples/scenarios/scoreboard

The fastest read is scenarios/scoreboard — one public channel, one publish loop, no sinks. Start there and walk down the table.

Scenarios

The seven scenarios from the original brief, each in its own directory:

# Directory Primitive Channel(s) Sink
7 scoreboard Publish on a public channel public:scoreboard.counter.ai_users none
4 heartbeat Periodic Publish driven by a ticker public:system.heartbeat.{service} none
3 feedback-flag PublishOrSink to a public ops channel public:agent.feedback.flagged slack
1 download-notify PublishOrSink to a per-user private channel private:webapp.user.{uid}.downloads email
2 agent-analysis Progress Publish + terminal PublishOrSink private:agent.analysis.{job}.progress email
5 nightly-report Date-scoped private channel, always-sink delivery private:cron.report.{date} email

Integration smoke tests

The two original examples remain — they are smoke tests for the library shape rather than scenario walkthroughs:

Directory Purpose
embedded Minimal parsec.New + OpenPublic + Publish.
notify-or-email Original PublishOrSink + email sink + refresh token demonstration.

Browser end-to-end

Directory Purpose
browser Full broker → websocket → browser path. Boots parsec, embeds an HTML page using centrifuge-js, and renders a 1 Hz heartbeat live. Open http://localhost:8000 after go run ./examples/browser. The narrative walkthrough (public + private + WebTransport variants) is at docs/src/getting-started/browser-client.md.

Conventions

Every scenario example:

  • Uses parsec.New directly (no CLI shelling).
  • Builds channel names with channels.BuildName, not fmt.Sprintf.
  • Logs through log/slog, not fmt.Println.
  • Self-cancels via a context.WithTimeout so go run exits 0 without Ctrl-C.
  • Configures sinks against unreachable endpoints (closed SMTP port, in-process HTTP stub) so nothing is actually emailed or posted.

Directories

Path Synopsis
Browser end-to-end demo.
Browser end-to-end demo.
Embedded shows how a Go service uses parsec as a library.
Embedded shows how a Go service uses parsec as a library.
notify-or-email demonstrates PublishOrSink: if the user's browser session is still subscribed, ship to the channel; otherwise fall back to email.
notify-or-email demonstrates PublishOrSink: if the user's browser session is still subscribed, ship to the channel; otherwise fall back to email.
scenarios
agent-analysis command
Scenario 2 from the parsec brief:
Scenario 2 from the parsec brief:
download-notify command
Scenario 1 from the parsec brief:
Scenario 1 from the parsec brief:
feedback-flag command
Scenario 3 from the parsec brief:
Scenario 3 from the parsec brief:
heartbeat command
Scenario 4 from the parsec brief:
Scenario 4 from the parsec brief:
nightly-report command
Scenario 5 from the parsec brief:
Scenario 5 from the parsec brief:
scoreboard command
Scenario 7 from the parsec brief:
Scenario 7 from the parsec brief:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL