Open evgenykuzyakov opened 5 years ago
Posting my previous notes on the topic as well:
PromiseId {
nonce,
account
}
Promise {
id: PromiseId,
callback: MethodRef
args: ByteBuffer
}
Can we use promises instead of callbacks when communicating cross-shard?
let promise1 = contract1.withMana(10).doSomething(...);
let promise2 = contract2.withMana(10).doSomething(...);
return Promise.all([promise1, promise2]);
Promise can potentially be resolved outside of smart contract by original caller.
Also can be handled inside smart contract code:
promise.then(handleEverythingOk, handleError); // Handle in same contract
promise.then(contract3.withMana(10).handleEverythingOk, contract3.withMana(10).handleError); // Handle in other contract
// bound args serialized in caller shard together with promise id
// this allows easily passing context to callback
promise.then(handleEverythingOk.bind(...));
Some scratch options for the new API: