-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add promises #202
Add promises #202
Conversation
Requires denoland/std#202
What else is going to go into promises? Can you explain why you're against "util"? |
Perhaps a pool implementation (which I have) and likely some other helpers (see e.g. bluebird). util is not descriptive... at all. IMOT util is a blight (everything's a util 😭 ), naming is really important (and difficult), likely we'll refactor in the future but nevertheless we should make a best effort. Helpers for promises, as well as for generators (ala itertools), are things that should be in std. I remember there was an issue somewhere to discuss what would be in std - but I can't find it. |
I have neutral opinion about There are some different solutions:
I don't agree with 1, and 3 may become difficult to manage as time goes by. I respect @ry 's decision for this repository. We have to make some decision on #130 together. And by this case, I'm also concerned about usage of deno_std's namespace in deno.land/x/. I will open another issue... |
An argument could be made for dropping all the independent std modules in the registry, i.e. reference std solely under /x/std/... I'm not sure about that. (Though it would solve the relative/not found issue.) This PR is independent of #130. There's certainly more promise-related helpers that could be included to /promises/ (I added a couple already and have some follow up ideas), I don't think anything is gained by having deferred in its own file in this case. There is a larger question/issue: what else should be in std? |
I think we ought to remove Deno.land/x/http and other sub modules of std... I will do some work on this today. |
export class TimeoutError extends Error { | ||
constructor(ms: number) { | ||
const message = `Timeout after ${ms}ms`; | ||
super(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these two lines be combined?
super(message); | |
super(`Timeout after ${ms}ms`); |
Also, should this use something like Node’s ms
utility to display the elapsed time in a more friendly manner?
@ry should this also be in individual files: promises/deferred.ts promises/timeout.ts promises/delay.ts ?? |
This one is out of date - if you want to land this still - let's discuss on gitter |
@ry defer is useful (and already used in several projects) and would be good to add back to std somewhere, as are the others... Happy to re-land this, but want to know how you want it structured.
|
Move deferred from util/ to promises/.
Add delay and timeout promises.
cc @ry @keroxp #188 (also denoland/deno#1800 #201 etc.)
Note: This would also need promises to be added to the registry: https://github.com/denoland/registry/pull/57
I am sure there are several other useful promise constructs, but these were the first that came to mind.