Skip to content

Commit b095b73

Browse files
committed
docs: include examples for the types in the docs
1 parent 8145d55 commit b095b73

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

examples/threaded-worker/processor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export class Processor {
1010
output = new Pull()
1111
signal = new Publisher()
1212

13-
init: Promise<any>
14-
exit: Promise<any>
13+
init: Promise<void[]>
14+
exit: Promise<void[]>
1515

1616
constructor(threads: number = cpus().length) {
1717
console.log(`starting ${threads} worker threads`)
@@ -22,7 +22,7 @@ export class Processor {
2222
this.input.bind("inproc://input"),
2323
this.output.bind("inproc://output"),
2424
this.signal.bind("inproc://signal"),
25-
new Promise(resolve => {
25+
new Promise<void>(resolve => {
2626
setTimeout(resolve, 100)
2727
}),
2828
])

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"ts-node": "~10.9.2",
6060
"typedoc": "^0.27.6",
6161
"typedoc-plugin-dt-links": "^1.1.6",
62+
"typedoc-plugin-include-example": "^2.0.2",
6263
"typedoc-plugin-inline-sources": "^1.2.0",
6364
"typedoc-plugin-mdn-links": "^4.0.7",
6465
"typescript": "~4.9.5",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compat.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,16 @@ for (const key in shortOptions) {
732732
})
733733
}
734734

735+
/**
736+
* Create a new socket.
737+
*
738+
* @param type Type of socket to create.
739+
* @param options Options for the socket.
740+
*
741+
* @returns A new socket.
742+
*
743+
* @includeExample examples/v5-compat/index.js
744+
*/
735745
export function createSocket(type: SocketType, options: {[key: string]: any} = {}) {
736746
const sock = new Socket(type)
737747
for (const key in options) {

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,8 @@ allowMethods(Pair.prototype, ["send", "receive"])
982982
* water mark for a connected {@link Subscriber}, then any messages that would
983983
* be sent to the subscriber in question shall instead be dropped until the mute
984984
* state ends. The {@link Writable.send}() method will never block.
985+
*
986+
* @includeExample examples/pub-sub/publisher.ts
985987
*/
986988
export class Publisher extends Socket {
987989
/**
@@ -1030,6 +1032,8 @@ allowMethods(Publisher.prototype, ["send"])
10301032
* {@link Publisher}. Initially a {@link Subscriber} is not subscribed to any
10311033
* messages. Use {@link Subscriber.subscribe}() to specify which messages to
10321034
* subscribe to. This socket cannot send messages.
1035+
*
1036+
* @includeExample examples/pub-sub/subscriber.ts
10331037
*/
10341038
export class Subscriber extends Socket {
10351039
/**
@@ -1135,6 +1139,8 @@ allowMethods(Subscriber.prototype, ["receive"])
11351139
* If no services are available, then any send operation on the socket shall
11361140
* block until at least one service becomes available. The REQ socket shall not
11371141
* discard messages.
1142+
*
1143+
* @includeExample examples/req-rep/client.ts
11381144
*/
11391145
export class Request extends Socket {
11401146
/**
@@ -1201,6 +1207,8 @@ allowMethods(Request.prototype, ["send", "receive"])
12011207
* among all clients, and each reply sent is routed to the client that issued
12021208
* the last request. If the original requester does not exist any more the reply
12031209
* is silently discarded.
1210+
*
1211+
* @includeExample examples/req-rep/server.ts
12041212
*/
12051213
export class Reply extends Socket {
12061214
/**
@@ -1232,6 +1240,9 @@ allowMethods(Reply.prototype, ["send", "receive"])
12321240
* When a {@link Dealer} is connected to a {@link Reply} socket, each message
12331241
* sent must consist of an empty message part, the delimiter, followed by one or
12341242
* more body parts.
1243+
*
1244+
* @includeExample examples/queue/index.ts
1245+
* @includeExample examples/queue/queue.ts
12351246
*/
12361247
export class Dealer extends Socket {
12371248
/**
@@ -1375,6 +1386,8 @@ allowMethods(Router.prototype, ["send", "receive"])
13751386
* A {@link Pull} socket is used by a pipeline node to receive messages from
13761387
* upstream pipeline nodes. Messages are fair-queued from among all connected
13771388
* upstream nodes. This socket cannot send messages.
1389+
*
1390+
* @includeExample examples/push-pull/worker.ts
13781391
*/
13791392
export class Pull extends Socket {
13801393
constructor(options?: SocketOptions<Pull>) {
@@ -1406,6 +1419,8 @@ allowMethods(Pull.prototype, ["receive"])
14061419
* at all, then {@link Writable.send}() will block until the mute state ends or
14071420
* at least one downstream node becomes available for sending; messages are not
14081421
* discarded.
1422+
*
1423+
* @includeExample examples/push-pull/producer.ts
14091424
*/
14101425
export class Push extends Socket {
14111426
constructor(options?: SocketOptions<Push>) {

typedoc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
"plugin": [
3232
"typedoc-plugin-dt-links",
3333
"typedoc-plugin-mdn-links",
34+
"typedoc-plugin-include-example"
3435
]
3536
}

0 commit comments

Comments
 (0)