我希望延遲Promise的執行,直到提供用戶輸入。承諾處於掛起狀態
我想要做一個職位,但等到事情發生,就像這樣:
while (true) {
promiseForUserInput = pending;
strInput = rl.question("provide input"); //waits for user input
promiseForUserInput = resolved;
var resultOfUsersChoice = promiseForUserInput.then(function(input) {
return loadFromServer(input)
}).then(function(serverResponse) {
console.log(serverResponse)
});
}
這可能嗎?我是否需要閱讀工廠功能?
在你的代碼中,'rl.question(「提供輸入」)'會阻止執行並等待輸入。你是否想等到從服務器獲得響應,然後再次提示用戶? – thefourtheye
是@thefourtheye,我想再次提示用戶 –