aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-09-25 15:22:05 -0700
committerGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-09-25 15:22:12 -0700
commit9d9fcbbdeb6803f7bda9690e9ca0e5b1ef123b07 (patch)
tree70f97790dc02dec6f641565765d88e0b14da394e
parentcd09bb0e9bcaf28806e2c3d05edc320af7a70507 (diff)
downloadbun-9d9fcbbdeb6803f7bda9690e9ca0e5b1ef123b07.tar.gz
bun-9d9fcbbdeb6803f7bda9690e9ca0e5b1ef123b07.tar.zst
bun-9d9fcbbdeb6803f7bda9690e9ca0e5b1ef123b07.zip
Update docs
-rw-r--r--docs/api/websockets.md15
-rw-r--r--docs/cli/run.md8
2 files changed, 19 insertions, 4 deletions
diff --git a/docs/api/websockets.md b/docs/api/websockets.md
index 7595f2c8a..4e55b8761 100644
--- a/docs/api/websockets.md
+++ b/docs/api/websockets.md
@@ -161,7 +161,7 @@ socket.addEventListener("message", event => {
### Pub/Sub
-Bun's `ServerWebSocket` implementation implements a native publish-subscribe API for topic-based broadcasting. Individual sockets can `.subscribe()` to a topic (specified with a string identifier) and `.publish()` messages to all other subscribers to that topic. This topic-based broadcast API is similar to [MQTT](https://en.wikipedia.org/wiki/MQTT) and [Redis Pub/Sub](https://redis.io/topics/pubsub).
+Bun's `ServerWebSocket` implementation implements a native publish-subscribe API for topic-based broadcasting. Individual sockets can `.subscribe()` to a topic (specified with a string identifier) and `.publish()` messages to all other subscribers to that topic (excluding itself). This topic-based broadcast API is similar to [MQTT](https://en.wikipedia.org/wiki/MQTT) and [Redis Pub/Sub](https://redis.io/topics/pubsub).
```ts
const server = Bun.serve<{ username: string }>({
@@ -200,7 +200,18 @@ const server = Bun.serve<{ username: string }>({
console.log(`Listening on ${server.hostname}:${server.port}`);
```
-Calling `.publish(data)` will send the message to all subscribers of a topic _except_ the socket that called `.publish()`.
+Calling `.publish(data)` will send the message to all subscribers of a topic _except_ the socket that called `.publish()`. To send a message to all subscribers of a topic, use the `.publish()` method on the `Server` instance.
+
+```ts
+const server = Bun.serve({
+ websocket: {
+ // ...
+ },
+});
+
+// listen for some external event
+server.publish("the-group-chat", "Hello world");
+```
### Compression
diff --git a/docs/cli/run.md b/docs/cli/run.md
index 5172f0fa4..de17093cb 100644
--- a/docs/cli/run.md
+++ b/docs/cli/run.md
@@ -89,6 +89,10 @@ $ bun --smol run index.tsx
Compare to `npm run <script>` or `yarn <script>`
{% /note %}
+```sh
+$ bun [bun flags] run <script> [script flags]
+```
+
Your `package.json` can define a number of named `"scripts"` that correspond to shell commands.
```jsonc
@@ -101,10 +105,10 @@ Your `package.json` can define a number of named `"scripts"` that correspond to
}
```
-Use `bun <script>` or `bun run <script>` to execute these scripts.
+Use `bun run <script>` to execute these scripts.
```bash
-$ bun clean
+$ bun run clean
$ rm -rf dist && echo 'Done.'
Cleaning...
Done.