v8go worker pool
December 7th, 2022
In my project Pipet, I wanted to do some trivial concurrency with v8go. I was dismayed for find out the v8 isolates cannot be accessed across threads. goroutines are not guaranteed to be on the same thread (they can be migrated to other threads), which means that you cannot use the same v8go isolate across goroutines.
This gist is the result of me trying to see what I can make work. Namely, creating a process that executes trivial JavaScript expressions instantly and “cleaning up” the isolate afterwards so it’s ready for the next expression. Finally, being able to cancel the workers from the main thread, though I don’t know how useful this really is, as most things sent over to v8 should be idempotent because the V8 VM should be considered unreliable.
As a side note, golang’s technical writers remain intensely impressive to me, as I find myself finding slides from 2012 when thinking about implementing webhooks