0

I was trying to find multithreading support for JavaScript, and then came across napa, but in the list of supported API, there's no buffer.
But in the project I've been working, we are passing buffer as an argument to functions which are required to be multithreaded,

  • can we use node zone from another zone for computing calculations regarding buffer?
  • If so how? If not, is there any other way or should I switch to using other library which unfortunately have much higher overhead cost?

EDIT:- I am trying to implement multithreading where we require something like the following class to be transported:-

class Multi{
  a(){
    ...
    returns buffer; 
  }
  ... other properties
}
Naveen
  • 3
  • 3

1 Answers1

0

While Napa.js does not directly support Buffer itself, it supports a range of "transportable" JavaScript types including Uint8Array, ArrayBuffer, and SharedArrayBuffer. Instances of Buffer are also instances of Uint8Array (here), so you can send and receive Uint8Array or Uint16Array objects.

You can check this post to see how you can convert buffers to and from Uint8Array objects. Keep in mind that since Napa.js currently does not directly support Buffer module, these conversions should take place in the main thread and not the workers. But you can normally operate on the typed arrays inside the zone workers.

Hope this helps!

Behrooz
  • 1,297
  • 10
  • 19