Show HN: LazyPromise = Observable – Signals

(github.com)

25 points | by ivan7237d 5 days ago

5 comments

  • guntis_dev 20 minutes ago
    Quick 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([promise, cancelPromise])
      
        return {
          promise: wrappedPromise,
          cancel: cancel,
        }
      }
  • nullzzz 53 minutes ago
    Interesting 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.

  • lgas 1 hour ago
    Do you want monads? Because this is how you get monads.
  • conartist6 2 hours ago
    Interesting, 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.
  • MuffinFlavored 2 hours ago
    > except you can optionally return a teardown function, for example:

    Kind of reminds me of https://doc.rust-lang.org/rust-by-example/trait/drop.html