Skip to content

Commit ad38ee1

Browse files
committed
fix: fix finalization of thread-safe poller
1 parent d79406b commit ad38ee1

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Diff for: .github/workflows/docs.yml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v4
2929

30-
3130
- name: Cache
3231
uses: actions/cache@v4
3332
with:

Diff for: src/draft.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,22 @@ interface RadioGroupOptions {
4141
export interface Radio extends Writable<MessageLike, [RadioGroupOptions]> {}
4242
allowMethods(Radio.prototype, ["send"])
4343

44-
const join = (
45-
Socket.prototype as Socket & {
46-
join: (value: Array<string | Buffer>) => void
47-
}
48-
).join
49-
const leave = (
50-
Socket.prototype as Socket & {
51-
leave: (value: Array<string | Buffer>) => void
52-
}
53-
).leave
54-
5544
export class Dish extends Socket {
5645
constructor(options?: SocketOptions<Dish>) {
5746
super(SocketType.Dish, options)
5847
}
5948

6049
join(...values: Array<Buffer | string>): void {
50+
const {join} = Socket.prototype as Socket & {
51+
join: (value: Array<string | Buffer>) => void
52+
}
6153
join(values)
6254
}
6355

6456
leave(...values: Array<Buffer | string>): void {
57+
const {leave} = Socket.prototype as Socket & {
58+
leave: (value: Array<string | Buffer>) => void
59+
}
6560
leave(values)
6661
}
6762
}

Diff for: src/socket.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ Socket::Socket(const Napi::CallbackInfo& info)
140140

141141
/* Callback to free the underlying poller. Move the poller to transfer
142142
ownership after the constructor has completed. */
143-
finalize = [&]() {
144-
[[maybe_unused]] auto err = zmq_poller_destroy(&poll);
145-
assert(err == 0);
143+
finalize = [poll]() mutable {
144+
if (poll != nullptr) {
145+
[[maybe_unused]] auto err = zmq_poller_destroy(&poll);
146+
assert(err == 0);
147+
poll = nullptr;
148+
}
146149
};
147150

148151
if (zmq_poller_add(poll, socket, nullptr, ZMQ_POLLIN | ZMQ_POLLOUT) < 0) {

0 commit comments

Comments
 (0)