|
|
|
|
|
by guntis_dev
171 days 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,
}
}
|
|