src/nodejs/jsworker_threads

    Dark Mode
Search:
Group by:

  • Multithreading, Thread Pool.

Types

MessageChannel {.importjs: "worker_threads.MessageChannel".} = ref object of JsRoot
https://nodejs.org/api/worker_threads.html#worker_threads_class_messagechannel
MessagePort {.importjs: "worker_threads.MessagePort".} = ref object of JsRoot
https://nodejs.org/api/worker_threads.html#worker_threads_class_messageport
Worker {.importjs: "worker_threads.Worker".} = ref object of JsRoot
  performance*: JsObject     ## https://nodejs.org/api/worker_threads.html#worker_threads_worker_performance
  resourceLimits*: JsObject  ## https://nodejs.org/api/worker_threads.html#worker_threads_worker_resourcelimits_1
  threadId*: cint            ## https://nodejs.org/api/worker_threads.html#worker_threads_worker_threadid_1
  
https://nodejs.org/api/worker_threads.html#worker_threads_class_worker

Procs

func close(self: BroadcastChannel or MessagePort) {.importjs: "#.$1()",
    discardable, ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_broadcastchannel_close
func getEnvironmentData(self: auto): auto {.importjs: "worker_threads.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_getenvironmentdata_key
func importCluster() {.importjs: "import * as worker_threads from \'worker_threads\'@",
                       ...raises: [], tags: [].}
Alias for import * as module_name from 'module_name';. Must be called once before using the module
func isMainThread(): bool {.importjs: "worker_threads.$1()", ...raises: [],
                            tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_ismainthread
func markAsUntransferable(objct: JsObject) {.importjs: "worker_threads.$1(#)",
    ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_markasuntransferable_object
func moveMessagePortToContext(port: MessagePort; contextifiedSandbox: JsObject): MessagePort {.
    importjs: "worker_threads.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_movemessageporttocontext_port_contextifiedsandbox
func newBroadcastChannel(name: auto): BroadcastChannel {.
    importjs: "(new BroadcastChannel(#))", ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_new_broadcastchannel_name
func newWorker(filename: cstring): Worker {.importjs: "(new Worker(#))",
    ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_new_worker_filename_options
func newWorker(filename: cstring; options: JsObject): Worker {.
    importjs: "(new Worker(#, #))", ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_new_worker_filename_options
func on[T](self: MessagePort; callback: T) {.importjs: "#.on(#)", discardable,
    ...raises: [], tags: [].}
func postMessage(self: BroadcastChannel or MessagePort or Worker; message: auto) {.
    importjs: "#.$1(#)", discardable, ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_broadcastchannel_postmessage_message
func postMessage(self: MessagePort or Worker; message: auto;
                 transferList: openArray[JsObject]) {.importjs: "#.$1(#, #)",
    discardable, ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_port_postmessage_value_transferlist
func receiveMessageOnPort(port: MessagePort): JsObject {.
    importjs: "worker_threads.$1(#)", ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_receivemessageonport_port
func refs(self: BroadcastChannel or MessagePort or Worker) {.
    importjs: "#.ref()", discardable, ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_broadcastchannel_ref
func requireCluster() {.importjs: "const worker_threads = require(\'worker_threads\')@",
                        ...raises: [], tags: [].}
Alias for const module_name = require('module_name');. Must be called once before using the module
func setEnvironmentData(key: auto; value: auto) {.
    importjs: "worker_threads.$1(#)", discardable, ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_setenvironmentdata_key_value
func start(self: MessagePort) {.importjs: "#.$1()", discardable, ...raises: [],
                                tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_port_start
func terminate(self: Worker): Future[cstring] {.importjs: "#.$1()", ...raises: [],
    tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_worker_terminate
func unrefs(self: BroadcastChannel or MessagePort or Worker) {.
    importjs: "#.unref()", discardable, ...raises: [], tags: [].}
https://nodejs.org/api/worker_threads.html#worker_threads_broadcastchannel_unref

Templates

template onClose(self: MessagePort; callback)
Alias for self.on(event = cstring("close"), callback).
template onError(self: MessagePort or Worker; callback)
Alias for self.on(event = cstring("error"), callback).
template onExit(self: MessagePort or Worker; callback)
Alias for self.on(event = cstring("exit"), callback).
template onMessage(self: MessagePort or Worker; callback)
Alias for self.on(event = cstring("message"), callback).
template onOnline(self: Worker; callback)
Alias for self.on(event = cstring("online"), callback).