Has anyone ever used a "web worker" in SuiteScript...
# suitescript
m
Has anyone ever used a "web worker" in SuiteScript 2.1?
b
thats more a javascript question, suitescript has very little to do with it
m
I know what I asked though. So I take it no one has really attempted using a web worker while executing suitescript?
b
you can anywhere you can add javascript, though you tend to be more restricted on the same origin policy on the workers since you dont actually control urls in netsuite
m
Goootcha... So in theory I could use one...
b
yes
m
Interesting. Not that I've necessarily had to use one yet, but I'm wondering if I could ever avoid using promises by using web workers for promise like things.
I come from a background with Elixir and in that language one can spin up async processes very easy for certain async operations.
But like... It was built for that where JavaScript's execution really wasn't but there are moments where I might want something async none the less but would want to avoid promises.
b
there isnt really anything useful in suitescript you can offload to a worker
m
You're probably right about that 🤔 I'm putting together some MR right now that I'm intending to use a web worker on that simply returns "hello world" to even see if it's possible.
b
web workers are for the web, they require a browser
👍 1
w
I have a subset sum algorithm that I wanted to put into a web worker. But never got around to learning/implementing it.
m
Like Battk said, I think you will need a browser. I tested with a MapReduce and got nothing. It doesn't continue executing after
const myWorker = new Worker("/SuiteScripts/my_worker.js")
The pathing I think should work because it works in a define if I were to reference some other script that I was using like a library. It might work in some client side script I suppose.
w
It is client side in this case.
m
@marth141 That would be a worker thread on the server side, a module available in NodeJs https://nodejs.org/api/worker_threads.html#worker-threads, but unfortunately it's not accessible from SuiteScript. With how NetSuite is setup to use JavaScript/NodeJs many of the native node modules are essentially blocked from being used in SuiteScript.
😭 1
s
AFAIK, NetSuite doesn't use NodeJS in any form.
It's the Graal JS engine (SS 2.1) last I heard.
m
Graal actually uses Node under the hood, but it can be used in two modes, one of them blocks most of the native node modules.
I'm mean run node code, sorry not under the hood
s
indeed, the API surface is just the restricted subset documented for us; nothing Graal or node-specific seems exposed.
So long story short - any lower level multithreading like 'web workers' is going to be browser only for now...
Though I agree with @battk the opportunities for it are limited in my experience with actual business requirements for these NS projects.
Also thanks @Matt Carter - I never gave it much thought but good to know Graal is node compatible behind the scenes at least. It would certainly be interesting if they enabled that completely for SuiteScript. Then again, may open the floodgates to bloated scripts. Meh, maybe SuiteScript 3.0? Though I still think SuiteScript 3.0 should just be NFT/TS :)
m
@Shawn Talbert LOL. I think Graal is long way from that point. Graal has a Node.js mode and a Java mode. The Java mode only exposes a special context object to the JS and the native built-ins for Node are not exposed on the context object currently. Conversely, you can access Java from JS with Graal. Never tried it in NetSuite, it's most likely blocked as its a manual dependency to be turned on in Graal.