Exidex
Exidex2mo ago

Pass JS function to an Op that can be called after the Op ends

Is there a way to have JS function to an Op that can be called after the Op ends? The problem is that to call a function, v8::HandleScope is needed but only the reference to it is passed to an op. The use case is: the op registers filesystem watcher and when change detected it should call js function that was passed as a parameter to and op. The runtime is kept running by a pending promise at another not related place. Also I am still using op v1 so something may have changed in v2 which I am not aware of
2 Replies
bartlomieju
bartlomieju2mo ago
It can't be done using an op. You will have to store the function as a v8::Global in some state and then invoke it manually on file changes
Exidex
ExidexOP2mo ago
Thought of doing that but to invoke it manually you still need a HandleScope, which basically comes from either an op or from JsRuntime which has same restriction. Either way, I was able to move the filesystem watching into JS which resolved the issue