2
在pg-promise
我有,我需要觸發內幕交易如果需要的話,可以回滾不會導致調用交易的情況時,錯誤回滾:pg-promise有沒有辦法觸發不會影響外部事務的內部事務?
var db = pgp()(connection);
db.task(function (tk){
tk.method(/* Logic used to decide if I need to continue */)
.then(function(data){
if (!data) return;
tk.tx(function*(tx){
// Somewhere in here I need to fire another transaction that I don't care if it fails
// but I need things to roll back inside of it should it fail
// without cause this tx to fail
})
})
})
我什麼都如果內部事務失敗,而不是內部事務回滾,並且外部事務繼續執行後面的邏輯,那麼到目前爲止嘗試的操作只是導致外部事務(tx
)回滾。如果子事務失敗,是否有可靠的方法導致內部事務不會導致tx
回滾?
作爲補充:當我嘗試使用Bluebird
Promise.some(tx1, tx2)
作爲失敗原因tx
回滾而其他tx#失敗並回滾時也失敗。內pg-promise
我很好奇,如果是因爲我們被鎖定到pg-promise的舊版本。我將檢查github上的提交歷史記錄以及可能的解決方案。 –
@RobertMennell可能是因爲你在混合使用ES6生成器,那些可能會很棘手,容易犯錯誤,你應該或不應該使用'yield';) –
謝謝指出!沒有想到這一點,但對每個追隨我的人都會有所幫助 –