Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/threadsafe_function.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub const ReleaseMode = enum(c.napi_threadsafe_function_release_mode) {
abort = c.napi_tsfn_abort,
};

pub const default_max_queue_size: usize = 1024;

pub fn ThreadSafeFunction(comptime Context: type, comptime CallData: type) type {
return struct {
tsfn: c.napi_threadsafe_function,
Expand All @@ -96,14 +98,21 @@ pub fn ThreadSafeFunction(comptime Context: type, comptime CallData: type) type
comptime finalize_cb: ?FinalizeCallback(Context),
comptime call_js_cb: ?ThreadSafeCallJsCallback(Context, CallData),
) NapiError!Self {
if (initial_thread_count == 0) return error.InvalidArg;

const queue_size = if (max_queue_size == 0)
default_max_queue_size
else
max_queue_size;

var tsfn: c.napi_threadsafe_function = undefined;

try status.check(c.napi_create_threadsafe_function(
env.env,
if (func) |f| f.value else null,
if (async_resource) |r| r.value else null,
async_resource_name.value,
max_queue_size,
queue_size,
initial_thread_count,
context, // finalize_data
if (finalize_cb) |cb| wrapFinalizeCallback(Context, cb) else null,
Expand Down