TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Why don't languages that support Promises include timeouts?

8 pointsby 0x0aff374668over 5 years ago
I've been programming with promises for several years now, and I find myself using a common pattern of adding a race timeout promise. It seems like a useful feature, why isn't it implicit when dealing with deferred execution? I run into very few cases where an infinite timeout period makes sense.

2 comments

komonover 5 years ago
You&#x27;re not the only person to be asking this question recently!<p>Kyle Simpson (@getify on twitter and github) of You Don&#x27;t Know JS fame has been working on a library for Javascript that wraps generators in a way that:<p>a) lets you use other Promise workflows to interact with them<p>b) lets you create a cancellation token that can be passed to a chain of asynchronous work to allow jobs to be cancelled all the way down that chain<p>among other goodies. Even if you&#x27;re not working in the JS space, it&#x27;s some really cool work to read about[1]<p>[1]<a href="https:&#x2F;&#x2F;github.com&#x2F;getify&#x2F;CAF" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;getify&#x2F;CAF</a>
评论 #21667292 未加载
SamReidHughesover 5 years ago
Well, you have to cancel the task, not ignore it. So you need some standard cancellation hook. And that generally has to be something explicitly handled by the task in question; it cannot automatically percolate all the way down to the deepest sub-task.<p>If your promise lib has cancellation built in, then adding a timeout to one is easy.
评论 #21667283 未加载