You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently all calls to the op-cli are using spawnSync to block until op-cli has a result. This causes issues when you don't want to block the event loop. Is there planned support for async execution (with Promise as result)?
Just as a hint, here is what I do to wrap calls to op-js in a Promise-wrapped Worker thread:
op-cli-worker.js:
'use strict';const{
parentPort, workerData,}=require('node:worker_threads');const[fName,args]=workerData;constopJs=require('@1password/op-js');// Resolve string in the form of 'vault.list' to the actual functionconsttheFunction=fName.split('.').reduce((o,i)=>o[i],opJs);if(typeoftheFunction!=='function'){parentPort.postMessage({error: newError(`Function ${fName} not found`)});}try{constresult=theFunction(...args);parentPort.postMessage({result});}catch(error){parentPort.postMessage({error});}
Activity
jodyheavener commentedon Sep 19, 2023
Thanks for filing @basert - this seems like a great idea. I'm slating it for review.
dreusel commentedon Feb 22, 2024
Just as a hint, here is what I do to wrap calls to op-js in a Promise-wrapped Worker thread:
op-cli-worker.js:
And in your application:
Instead of the usual
I do:
[edit: Put the worker code in a separate file as the original way using a stringified function had some weird side-effects]