-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Documentation async #12979
Documentation async #12979
Conversation
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.
This doesn't belong in the manual as it's not a language feature, it should probably be in a separate document or in asyncdispatch
.
Maybe an async tutorial as well? |
I agree with @mratsim that also a Tutorial can be nice, Maybe Tutorials improvement can be part of another PR, to keep diff easy to review and merge. |
IMHO this should be an async tutorial and the asyncdispatch modules should link to the tutorial. |
We all agree on that. |
lib/pure/asyncdispatch.nim
Outdated
## .. code-block:: nim | ||
## proc example() {.async.} = | ||
## echo "asyncCheck Example" | ||
## | ||
## asyncCheck example() |
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.
I don't see the point of this example, either remove it or give it a descriptive heading.
lib/pure/asyncdispatch.nim
Outdated
## waitFor | ||
## ------- | ||
## | ||
## ``waitFor`` is similiar to ``asyncCheck`` but it will wait for the ``Future``. |
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.
## ``waitFor`` is similiar to ``asyncCheck`` but it will wait for the ``Future``. | |
## ``waitFor`` is similar to ``asyncCheck`` but it will wait for the ``Future``. |
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.
This is a bad description though. waitFor
blocks the current thread and runs the async IO loop until the future finishes, it's not really comparable to asyncCheck
.
lib/pure/asyncdispatch.nim
Outdated
## ``await`` will wait for the ``Future``, and gives you the contents inside the ``Future``, | ||
## ``await`` only available inside a function with the ``{.async.}`` or ``{.multisync.}`` Pragmas. | ||
## | ||
## The usage and features are the same of ``waitFor`` (mentioned above). |
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.
usage is the same, I don't understand what features there are to speak of which are the same.
lib/pure/asyncdispatch.nim
Outdated
## then the same function can be used on asynchronous *and* synchronous code, | ||
## you can think of it as a function that is async or sync depending on how you use it. | ||
## | ||
## The usage and features are the same of ``{.async.}`` (mentioned above). Example: |
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.
again with the "features", that tells the reader nothing and is misleading.
lib/pure/asyncdispatch.nim
Outdated
## | ||
## echo Client().multisync_function() # Sync | ||
## | ||
## This is one of the reasons Nim wont use syntax like ``async proc fetch() =`` like other languages, |
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.
*won't
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.
How is this one of the reasons?
lib/pure/asyncdispatch.nim
Outdated
## echo Client().multisync_function() # Sync | ||
## | ||
## This is one of the reasons Nim wont use syntax like ``async proc fetch() =`` like other languages, | ||
## also you dont have to repeat your procedure twice like ``async proc aio_fetch() =`` and ``proc fetch() =``, |
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.
*don't...
lib/pure/asyncdispatch.nim
Outdated
## Client = HttpClient | ||
## AsyncClient = AsyncHttpClient | ||
## | ||
## proc multisync_function(this: Client | AsyncClient): Future[string] {.multisync.} = |
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.
camelCase is the convention
## ================================ ============ ========= ======= | ||
## Waits for the Future to complete No Yes Yes | ||
## Ignores the Future Yes No No | ||
## Returns result inside Future No No Yes |
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.
"Returns result inside Future" waitFor should be yes?
Example:
import asyncdispatch
proc foo(): Future[int] {.async.} =
return 42
echo waitFor foo()
I really like this. I wish this was there when I started to learn about async. The async only clicked for me when I learned that:
Off-topic, but if it was up to me I would:
|
...but it does wrap the result on a |
|
Sorry I meant do that in the definitions of the proc. I know it does that
on the actual return, I wish it would do that in the signature as well to
match.
…On Sat, Jan 11, 2020, 3:30 PM Andy Davidoff ***@***.***> wrote:
return wraps its argument but result is always Future.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12979?email_source=notifications&email_token=AAA6X7DCRESLFDCZD6JHMT3Q5JJBBA5CNFSM4KAKLK22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIWNOJQ#issuecomment-573364006>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA6X7BKCSV4QKGCZMKSMNLQ5JJBBANCNFSM4KAKLK2Q>
.
|
The problem with that, assuming you didn't have the burden of code in the wild, is that it's hiding even more magic. I wish |
It is too late to change how {.async.} works now. Sorry for derailing the discussion. I think the docs are good. |
So, if we all agree on that, can we close this PR and use its content as a basis for |
Feel free to close if is the way forward. |
I think it is. Now waiting for your async tutorial :) |
What's the progress of this tutorial? |
We don't have a tutorial so we should take the doc improvements. Please continue your work @juancarlospaco ! |
This also fixes #5021 |
Succeeded by #19738 |
🙂