I’m having great success with Workers and Workers KV. So much so that I’m now moving on to optimizations.
I have a small nginx server to which my CF Worker scripts send log messages to. This has worked great for development and debugging, but it’s not ideal. Each call to my log function create a whole new connection to the log server, and there’s no ordering of messages.
Ideally, I’d like to solve this by standing up a Dedicated Web Worker thread at the start of my script, which opens one connection to my log server. Then, each call to write a log message actually sends a message to the Web Worker. That message is then forwarded to my log server.
It looks like this is possible in JS save one detail. All the examples do setup like:
var worker = new Worker(`thread.js`)
thread.js is a separate script file on the server. Unfortunately, that doesn’t apply here. At least, I don’t think it does…
So my question is:
a) How do I declare a separate script file in my script?
b) How else can I establish a background thread for a single, sustained I/O connection?