nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.24k stars 1.46k forks source link

Multiple callbacks in a Future #5200

Open funny-falcon opened 7 years ago

funny-falcon commented 7 years ago

It is quite strange that Future may have only one callback. It limits its composability.

Araq commented 7 years ago

Why? Shouldn't the callback "compose" the stuff?

funny-falcon commented 7 years ago

No, cause many libraries works only with default callback, and they will ovewrite "composing" callback.

krux02 commented 7 years ago

Can you give an example on what you would like to be able to do?

funny-falcon commented 7 years ago

For example, i would like to store a future in a table by a key, and have many consumers to be informed when future will be completed. And I want it to be transparently supported with all standard library.

In simple words, I want Javascript Promise or Dart's Future or C# Task:

They all may have multiple consumers of result. It is really useful feature, and it will be quite painful to implement outside of standard library

krux02 commented 7 years ago

What you want is the Future to have an error callback. Then you should say so in the title.

funny-falcon commented 7 years ago

No, I didn't mean error callback. Error callback is not as important as multiple callbacks. Error could be signaled with special result value. Mutiple callbacks are much more useful/important.

funny-falcon commented 7 years ago

Promise#then and Future#then could be called several times, and all passed callbacks will be executed.

Any way, I'm not Nim's user (and Future's single callback is one of reasons), so you may close the issue.

But I bet, it will be raised again by other users.

Araq commented 7 years ago

Any way, I'm not Nim's user (and Future's single callback is one of reasons), so you may close the issue.

Don't worry, that's not how things work here. :-)

dom96 commented 7 years ago

I'll have to think about this more but my initial thoughts is that this is a good idea.

andreaferretti commented 7 years ago

Related: https://github.com/nim-lang/Nim/issues/5731

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.