0
나는 (여전히 학습) 내 웹 사이트에 약속을 사용하고 나는이 차이가 있는지 알고 싶습니다 :차이 둘 사이의 구현
return promise
.then(ctxTransport.getTransportById(idTran, transport))
.then(checkLocking)
.fail(somethingWrong);
이 :
return promise
.then(function() { return ctxTransport.getTransportById(idTran, transport); })
.then(function() { return checkLocking(); })
.fail(somethingWrong);
첫 번째 구현에서는 오류가 발생합니다.
var getTransportById = function (transportId, transportObservable, forceRemote) {
// Input: transportId: the id of the transport to retrieve
// Input: forceRemote: boolean to force the fetch from server
// Output: transportObservable: an observable filled with the transport
...
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
function querySucceeded(data) {
transportObservable(data.results[0]);
}
};
function checkLocking() {
var now = new Date();
transport().lockedById(5);
transport().lockedTime(now);
return ctxTransport.saveChanges(SILENTSAVE);
}
function somethingWrong(error) {
var msg = 'Error retreiving data. ' + error.message;
logError(msg, error);
throw error;
}
감사합니다.