我正在做的事情涉及按顺序运行一系列child_process.spawn()(进行一些设置,然后运行调用者感兴趣的实际多肉命令,然后进行一些清理).
就像是:
doAllTheThings()
.then(function(exitStatus){
// all the things were done
// and we've returned the exitStatus of
// a command in the middle of a chain
});
Run Code Online (Sandbox Code Playgroud)
在哪里doAllTheThings()是这样的:
function doAllTheThings() {
runSetupCommand()
.then(function(){
return runInterestingCommand();
})
.then(function(exitStatus){
return runTearDownCommand(exitStatus); // pass exitStatus along to return to caller
});
}
Run Code Online (Sandbox Code Playgroud)
在内部我正在使用child_process.spawn(),它返回一个EventEmitter,我实际上将close事件的结果runInterestingCommand()返回给调用者.
现在我还需要将data来自stdout和stderr的事件发送给调用者,调用者也来自EventEmitters.有没有办法让(Bluebird)Promises使用它,或者它们只是阻碍了发出多个事件的EventEmitters?
理想情况下,我希望能够写:
doAllTheThings()
.on('stdout', function(data){
// process a chunk of received stdout data
})
.on('stderr', function(data){ …Run Code Online (Sandbox Code Playgroud) 算法:
data[1-5]someDataToShowInModal.问题:如何等到用户点击模态的 OK 或 CANCEL 按钮?
在代码中我展示了两种可能的解决方案,但不知道如何实现它们:
将模态包装到 Promise 中。
使用state.doSave并以某种方式等到它被更改myModalComponent。
如果用户单击“确定”,则应用更改。
下面是伪代码,显示了我尝试实现的逻辑:
状态.js
modalTextSummary = {}
Run Code Online (Sandbox Code Playgroud)
动作.js
async myAction ({ state }) {
let modalClosed
let someDataToShowInModal = {}
let data1 = []
let data2 = []
let data3 = []
let data4 = []
let data5 = []
// #1. Push difference to "data[1-5]"
data1.push(xyz1)
data2.push(xyz2)
data3.push(xyz3)
data4.push(xyz4)
data5.push(xyz5)
// #2. Based on data[1-5] prepare "someDataToShowInModal"
someDataToShowInModal …Run Code Online (Sandbox Code Playgroud)