I stumbled upon the same (related) problem. Discussions here https://forum.dfinity.org/t/rxmo-update-examples/21029 and https://forum.dfinity.org/t/motoko-sharable-generics/9021/14
Additionally, I’d like to propose an enhancement to the Motoko promises system:
As it stands, promises in Motoko can’t be resolved or rejected externally from within the executor function. In contrast, JavaScript allows us to create and manage promise resolution outside of the initial executor context. Here’s an illustrative example in JavaScript:
(Deferred promise pattern)
var myResolution = null;
let myPromise = new Promise((resolve, reject) => {
myResolution ={resolve, reject}
});
setTimeout(() => {
// resolve it after 10sec
myResolution.resolve(123);
}, 10000);
let a = await myPromise();
// a = 123
You’ll have to currently write such things with callback functions. Not sure if deferred promises can fit, but would be nice to have.