Skip to content

Commit a372511

Browse files
authored
Merge pull request #661 from zeromq/update-deps [skip ci]
2 parents 819d419 + 180305b commit a372511

File tree

17 files changed

+1934
-1888
lines changed

17 files changed

+1934
-1888
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ jobs:
8282
8383
- name: Env map
8484
run: |
85-
if [ "${{ matrix.node_arch }}" = "ia32" ]; then
86-
echo "setup_node_arch=x86" > $GITHUB_ENV
87-
fi
85+
if [ "${{ matrix.node_arch }}" = "ia32" ]; then
86+
echo "setup_node_arch=x86" > $GITHUB_ENV
87+
fi
8888
shell: bash
8989

9090
- name: Setup Cpp

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/node_modules
66
pnpm-lock.yaml
77
/build
8+
/script/*.js
9+
/script/*.mjs

.vscode/launch.json

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
11
{
2-
"configurations": [
3-
{
4-
"name": "JS-Attach",
5-
"type": "node",
6-
"request": "attach",
7-
"port": 9229,
8-
"continueOnAttach": true,
9-
"autoAttachChildProcesses": true,
10-
"resolveSourceMapLocations": [
11-
"!**/node_modules/**",
12-
"!**/.vscode/extensions/hbenl.vscode-mocha-test-adapter-*/**"
13-
],
14-
"skipFiles": [
15-
"<node_internals>/**"
16-
],
17-
},
18-
{
19-
"type": "lldb",
20-
"request": "launch",
21-
"name": "Native-Launch",
22-
"preLaunchTask": "clean_build_debug",
23-
"program": "node",
24-
"suppressMultipleSessionWarning": true,
25-
"sourceLanguages": [
26-
"cpp"
27-
],
28-
"args": [
29-
"--inspect-brk=9229",
30-
"--expose-gc",
31-
"-r",
32-
"ts-node/register",
33-
"${workspaceFolder}/test/debug.ts"
34-
],
35-
}
36-
],
37-
"compounds": [
38-
{
39-
"name": "Node-Launch",
40-
"configurations": [
41-
"Native-Launch",
42-
"JS-Attach",
43-
]
44-
}
45-
]
2+
"configurations": [
3+
{
4+
"name": "JS-Attach",
5+
"type": "node",
6+
"request": "attach",
7+
"port": 9229,
8+
"continueOnAttach": true,
9+
"autoAttachChildProcesses": true,
10+
"resolveSourceMapLocations": [
11+
"!**/node_modules/**",
12+
"!**/.vscode/extensions/hbenl.vscode-mocha-test-adapter-*/**"
13+
],
14+
"skipFiles": ["<node_internals>/**"]
15+
},
16+
{
17+
"type": "lldb",
18+
"request": "launch",
19+
"name": "Native-Launch",
20+
"preLaunchTask": "clean_build_debug",
21+
"program": "node",
22+
"suppressMultipleSessionWarning": true,
23+
"sourceLanguages": ["cpp"],
24+
"args": [
25+
"--inspect-brk=9229",
26+
"--expose-gc",
27+
"-r",
28+
"ts-node/register",
29+
"${workspaceFolder}/test/debug.ts"
30+
]
31+
}
32+
],
33+
"compounds": [
34+
{
35+
"name": "Node-Launch",
36+
"configurations": ["Native-Launch", "JS-Attach"]
37+
}
38+
]
4639
}

.vscode/settings.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"mochaExplorer.parallel": true,
33
"mochaExplorer.globImplementation": "vscode",
4-
"mochaExplorer.nodeArgv": [
5-
"--expose-gc"
6-
],
4+
"mochaExplorer.nodeArgv": ["--expose-gc"],
75
"mochaExplorer.debuggerConfig": "JS-Attach",
86
"files.exclude": {
97
"**/.git": true,
@@ -16,6 +14,6 @@
1614
"**/script/*.mjs.map": true,
1715
"**/script/*.d.ts": true,
1816
"**/script/*.d.mts": true,
19-
"**/script/*.tsbuildinfo": true,
17+
"**/script/*.tsbuildinfo": true
2018
}
2119
}

.vscode/tasks.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"version": "2.0.0",
3-
"tasks": [
4-
{
5-
"label": "clean_build_debug",
6-
"type": "shell",
7-
"command": "pnpm clean.release && pnpm build.debug",
8-
}
9-
]
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "clean_build_debug",
6+
"type": "shell",
7+
"command": "pnpm clean.release && pnpm build.debug"
8+
}
9+
]
1010
}

README.md

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
iterators.
1111
- High performance.
1212
- Fully usable with TypeScript (3+).
13+
- Compatible with Zeromq 4/5 via "zeromq/v5-compat"
1314

1415
## Useful links
1516

@@ -51,14 +52,19 @@ Requirements for using prebuilt binaries:
5152

5253
The following platforms have a **prebuilt binary** available:
5354

55+
- Windows on x86/x86-64
56+
57+
Zeromq binaries on Windows 10 or older need
58+
[Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version)
59+
to be installed.
60+
5461
- Linux on x86-64 with libstdc++.so.6.0.21+ (glibc++ 3.4.21+), for example:
5562
- Debian 9+ (Stretch or later)
5663
- Ubuntu 16.04+ (Xenial or later)
5764
- CentOS 8+
5865
- Linux on x86-64 with musl, for example:
5966
- Alpine 3.3+
6067
- MacOS 10.9+ on x86-64
61-
- Windows on x86/x86-64
6268

6369
If a prebuilt binary is not available for your platform, installing will attempt
6470
to start a build from source.
@@ -161,11 +167,40 @@ macos_deployment_target="10.15"
161167

162168
## Examples
163169

164-
**Note:** These examples assume the reader is familiar with ZeroMQ. If you are
165-
new to ZeroMQ, please start with the
170+
Here some examples of different features are provided. More examples can be
171+
found in the [examples directory](examples).
172+
173+
You can also browse
174+
[the API reference documentation](http://zeromq.github.io/zeromq.js/globals.html)
175+
to see all socket types, methods & options as well as more detailed information
176+
about how to apply them.
177+
178+
**Note:** If you are new to ZeroMQ, please start with the
166179
[ZeroMQ documentation](https://zeromq.org/get-started/).
167180

168-
More examples can be found in the [examples directory](examples).
181+
### Basic Usage
182+
183+
ES modules:
184+
185+
```typescript
186+
import {Request} from "zeromq"
187+
// or as namespace
188+
import * as zmq from "zeromq"
189+
190+
const reqSock = new Request()
191+
//...
192+
const repSock = new zmq.Reply()
193+
```
194+
195+
Commonjs:
196+
197+
```js
198+
const zmq = require("zeromq")
199+
200+
const reqSock = new zmq.Request()
201+
//...
202+
const repSock = new zmq.Reply()
203+
```
169204

170205
### Push/Pull
171206

@@ -177,7 +212,7 @@ how a worker pulls information from the socket.
177212
Creates a producer to push information onto a socket.
178213

179214
```js
180-
const zmq = require("zeromq")
215+
import * as zmq from "zeromq"
181216

182217
async function run() {
183218
const sock = new zmq.Push()
@@ -201,7 +236,7 @@ run()
201236
Creates a worker to pull information from the socket.
202237

203238
```js
204-
const zmq = require("zeromq")
239+
import * as zmq from "zeromq"
205240

206241
async function run() {
207242
const sock = new zmq.Pull()
@@ -227,7 +262,7 @@ Publisher/Subscriber, application.
227262
Create the publisher which sends messages.
228263

229264
```js
230-
const zmq = require("zeromq")
265+
import * as zmq from "zeromq"
231266

232267
async function run() {
233268
const sock = new zmq.Publisher()
@@ -252,7 +287,7 @@ run()
252287
Create a subscriber to connect to a publisher's port to receive messages.
253288

254289
```js
255-
const zmq = require("zeromq")
290+
import * as zmq from "zeromq"
256291

257292
async function run() {
258293
const sock = new zmq.Subscriber()
@@ -281,7 +316,7 @@ This example illustrates a request from a client and a reply from a server.
281316
#### `client.js`
282317

283318
```js
284-
const zmq = require("zeromq")
319+
import * as zmq from "zeromq"
285320

286321
async function run() {
287322
const sock = new zmq.Request()
@@ -301,58 +336,22 @@ run()
301336
#### `server.js`
302337

303338
```js
304-
const zmq = require("zeromq")
339+
import * as zmq from "zeromq"
305340

306341
async function run() {
307342
const sock = new zmq.Reply()
308343

309344
await sock.bind("tcp://127.0.0.1:3000")
310345

311346
for await (const [msg] of sock) {
312-
await sock.send(2 * parseInt(msg, 10))
347+
await sock.send((2 * parseInt(msg.toString(), 10)).toString())
313348
}
314349
}
315350

316351
run()
317352
```
318353

319-
## TypeScript
320-
321-
This library provides typings for TypeScript version 3.0.x and later.
322-
323-
_Requirements_
324-
325-
- For TypeScript version >= 3:
326-
- [compilerOptions](https://www.typescriptlang.org/docs/handbook/compiler-options.html)
327-
- For TypeScript version < 3.6:
328-
- either set `compilerOptions.target` to `esnext` or later (e.g. `es2018`)
329-
- or add the following, or similar, libraries to `compilerOptions.lib` (and
330-
include their corresponding polyfills if needed): `es2015`,
331-
`ESNext.AsyncIterable`
332-
333-
_Example Usage_
334-
335-
```typescript
336-
import {Request} from "zeromq"
337-
// or as namespace
338-
import * as zmq from "zeromq"
339-
340-
const reqSock = new Request()
341-
//...
342-
const repSock = new zmq.Reply()
343-
```
344-
345-
### More examples
346-
347-
More advanced examples can be found in the [examples](examples) directory of
348-
this repository.
349-
350-
Or you can
351-
[browse the API reference documentation](http://zeromq.github.io/zeromq.js/globals.html)
352-
to see all socket types, methods & options as well as more detailed information
353-
about how to apply them.
354-
355-
### Compatibility layer for version 4/5
354+
## Zeromq 4 and 5 Compatibility layer
356355

357356
The next generation version of the library features a compatibility layer for
358357
ZeroMQ.js versions 4 and 5. This is recommended for users upgrading from
@@ -379,6 +378,20 @@ pub.bind("tcp://*:3456", err => {
379378
})
380379
```
381380

381+
## TypeScript
382+
383+
This library provides typings for TypeScript version 3.0.x and later.
384+
385+
_Requirements_
386+
387+
- For TypeScript version >= 3:
388+
- [compilerOptions](https://www.typescriptlang.org/docs/handbook/compiler-options.html)
389+
- For TypeScript version < 3.6:
390+
- either set `compilerOptions.target` to `esnext` or later (e.g. `es2018`)
391+
- or add the following, or similar, libraries to `compilerOptions.lib` (and
392+
include their corresponding polyfills if needed): `es2015`,
393+
`ESNext.AsyncIterable`
394+
382395
## Contribution
383396

384397
If you are interested in making contributions to this project, please read the

examples/pub-sub/publisher.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as zmq from "zeromq"
2+
3+
async function run() {
4+
const sock = new zmq.Publisher()
5+
6+
await sock.bind("tcp://127.0.0.1:3000")
7+
console.log("Publisher bound to port 3000")
8+
9+
while (true) {
10+
console.log("sending a multipart message envelope")
11+
await sock.send(["kitty cats", "meow!"])
12+
await new Promise(resolve => {
13+
setTimeout(resolve, 500)
14+
})
15+
}
16+
}
17+
18+
run()

examples/pub-sub/subscriber.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as zmq from "zeromq"
2+
3+
async function run() {
4+
const sock = new zmq.Subscriber()
5+
6+
sock.connect("tcp://127.0.0.1:3000")
7+
sock.subscribe("kitty cats")
8+
console.log("Subscriber connected to port 3000")
9+
10+
for await (const [topic, msg] of sock) {
11+
console.log(
12+
"received a message related to:",
13+
topic,
14+
"containing message:",
15+
msg,
16+
)
17+
}
18+
}
19+
20+
run()

examples/push-pull/producer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as zmq from "zeromq"
2+
3+
async function run() {
4+
const sock = new zmq.Push()
5+
6+
await sock.bind("tcp://127.0.0.1:3000")
7+
console.log("Producer bound to port 3000")
8+
9+
while (true) {
10+
await sock.send("some work")
11+
await new Promise(resolve => {
12+
setTimeout(resolve, 500)
13+
})
14+
}
15+
}
16+
17+
run()

0 commit comments

Comments
 (0)