Kind of reminds me of https://doc.rust-lang.org/rust-by-example/trait/drop.html
The two separate failure channels turn me off. Is this practical or does it introduce unwanted complexity in most cases?
Also wondering what are the Signals that are mentioned.
About the two error channels: what I tried to do is to make it really easy to not use typed errors when you don't need them. In that case your promise is typed as `LazyPromise<Value, never>`.
Signals is a reactive primitive that has been initially introduced in SolidJS framework and have then made their way to other frameworks like Angular.
function cancelablePromise() {
const promise = new Promise(resolve => setTimeout(resolve, 1000))
let cancel: () => void
const cancelPromise = new Promise((_, reject) => {
cancel = () => reject("promise canceled")
})
const wrappedPromise = Promise.race([promise, cancelPromise])
return {
promise: wrappedPromise,
cancel: cancel,
}
}
conartist6•1mo ago
ivan7237d•1mo ago