Skip to content

Commit

Permalink
fix: fix finalization of thread-safe poller
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 30, 2024
1 parent d79406b commit ad38ee1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
steps:
- uses: actions/checkout@v4


- name: Cache
uses: actions/cache@v4
with:
Expand Down
17 changes: 6 additions & 11 deletions src/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,22 @@ interface RadioGroupOptions {
export interface Radio extends Writable<MessageLike, [RadioGroupOptions]> {}
allowMethods(Radio.prototype, ["send"])

const join = (
Socket.prototype as Socket & {
join: (value: Array<string | Buffer>) => void
}
).join
const leave = (
Socket.prototype as Socket & {
leave: (value: Array<string | Buffer>) => void
}
).leave

export class Dish extends Socket {
constructor(options?: SocketOptions<Dish>) {
super(SocketType.Dish, options)
}

join(...values: Array<Buffer | string>): void {
const {join} = Socket.prototype as Socket & {
join: (value: Array<string | Buffer>) => void
}
join(values)
}

leave(...values: Array<Buffer | string>): void {
const {leave} = Socket.prototype as Socket & {
leave: (value: Array<string | Buffer>) => void
}
leave(values)
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ Socket::Socket(const Napi::CallbackInfo& info)

/* Callback to free the underlying poller. Move the poller to transfer
ownership after the constructor has completed. */
finalize = [&]() {
[[maybe_unused]] auto err = zmq_poller_destroy(&poll);
assert(err == 0);
finalize = [poll]() mutable {
if (poll != nullptr) {
[[maybe_unused]] auto err = zmq_poller_destroy(&poll);
assert(err == 0);
poll = nullptr;
}
};

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

0 comments on commit ad38ee1

Please sign in to comment.