Show HN: LazyPromise = Observable – Signals
1–10 of 11 posts
Re: Show HN: LazyPromise = Observable – Signals
#2Re: Show HN: LazyPromise = Observable – Signals
#3Kind of reminds me of https://doc.rust-lang.org/rust-by-example/trait/drop.html
Re: Show HN: LazyPromise = Observable – Signals
#4Re: Show HN: LazyPromise = Observable – Signals
#5The 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.
Re: Show HN: LazyPromise = Observable – Signals
#6 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,
}
}Re: Show HN: LazyPromise = Observable – Signals
#7Re: Show HN: LazyPromise = Observable – Signals
#8Interesting, interesting. It would take me a few hours of playing with this mechanism to know what I think of it as a primitive, but for me this solution is relevant to a problem I really have so I might take a look. Right now I just write methods that sometimes return a promise and sometimes don't.
Re: Show HN: LazyPromise = Observable – Signals
#9Quick question - would something like this cover the basic cancelable promise use case, or am I missing something important about what LazyPromise does differently? 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([pr…
Re: Show HN: LazyPromise = Observable – Signals
#10Interesting stuff! 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`.
Signals is a reactive primitive that has been initially introduced in SolidJS framework and have then made their way to other frameworks like Angular.