所以,我有一个像这样的代码.
getSomethingAsync(something)
.then(doSomethingAsync)
.then(function(d) {
_d = doSomethingSync(d);
return doSomethingAsyncNext(_d);
})
.then(function(val) {
//All done
})
.catch(err_handler);
Run Code Online (Sandbox Code Playgroud)
我想把它变成类似的东西.
getSomethingAsync(something)
.then(doSomethingAsync)
.then(doSomethingSync)
.then(doSomethingAsyncNext)
.then(function(val) {
//All done
})
.catch(err_handler);
Run Code Online (Sandbox Code Playgroud)
我应该改变doSomethingSync,它是:
function(data) {
// do a lot of things with data, throw errors for invalid data
return changed_data;
}
Run Code Online (Sandbox Code Playgroud)
至:
function(data) {
// do a lot of things with data, throw errors for invalid data
return new Promise(function(resolve,reject){
resolve(changed_data);
});
}
Run Code Online (Sandbox Code Playgroud)
要么:
function(data) {
return new Promise(function(resolve,reject){
// do a lot of …Run Code Online (Sandbox Code Playgroud)