Threading
Data frames and objects are serializable by default through the use of decorators. This allows data to be transmitted between threads. Threading is supported in OpenHPS through worker nodes and graphs that run one or more nodes in a pool of threads.
Creating a threaded node with callback
Master File
ts
import {ModelBuilder ,WorkerNode } from '@openhps/core';import * aspath from 'path';ModelBuilder .create ().from ().via (newWorkerNode ((builder ) => {const {SomeNode } =require (path .join (__dirname ,'./nodes/SomeNode',));builder .via (newSomeNode ());},{directory :__dirname ,poolSize : 1,},),).to (/* ... */).build ();
Creating a threaded node with file
Master File
ts
import {ModelBuilder ,WorkerNode } from '@openhps/core';ModelBuilder .create ().from ().via (newWorkerNode ("./SomeThread.ts",{directory :__dirname ,poolSize : 1,},),).to (/* ... */).build ();
Worker File
ts
import {CallbackNode ,DataFrame ,DataObject ,ModelBuilder } from '@openhps/core';export defaultModelBuilder .create ().from ().via (newCallbackNode (frame => {// Do something time consuming ...})).to ();