Skip to content
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

Closed
wants to merge 7 commits into from
Closed

Documentation async #12979

wants to merge 7 commits into from

Conversation

juancarlospaco
Copy link
Collaborator

  • Document Async. Only Documentation.
  • Includes MultiSync, asyncCheck, waitFor, await, etc.
  • Includes Examples.

🙂

Copy link
Contributor

@dom96 dom96 left a 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.

@mratsim
Copy link
Collaborator

mratsim commented Dec 30, 2019

Maybe an async tutorial as well?

@juancarlospaco
Copy link
Collaborator Author

I agree with @mratsim that also a Tutorial can be nice,
but Tutorials on asyncdispatch module feels weird and probably hard to discover for new users.

Maybe Tutorials improvement can be part of another PR, to keep diff easy to review and merge.

@Araq
Copy link
Member

Araq commented Dec 30, 2019

IMHO this should be an async tutorial and the asyncdispatch modules should link to the tutorial.

@juancarlospaco
Copy link
Collaborator Author

We all agree on that.
But if you want to close this one close it, one way or another users will not complain for too much Documentation. :P

Comment on lines 159 to 163
## .. code-block:: nim
## proc example() {.async.} =
## echo "asyncCheck Example"
##
## asyncCheck example()
Copy link
Contributor

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.

## waitFor
## -------
##
## ``waitFor`` is similiar to ``asyncCheck`` but it will wait for the ``Future``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## ``waitFor`` is similiar to ``asyncCheck`` but it will wait for the ``Future``.
## ``waitFor`` is similar to ``asyncCheck`` but it will wait for the ``Future``.

Copy link
Contributor

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.

## ``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).
Copy link
Contributor

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 Show resolved Hide resolved
lib/pure/asyncdispatch.nim Outdated Show resolved Hide resolved
## 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:
Copy link
Contributor

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 Show resolved Hide resolved
##
## echo Client().multisync_function() # Sync
##
## This is one of the reasons Nim wont use syntax like ``async proc fetch() =`` like other languages,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*won't

Copy link
Contributor

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?

## 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() =``,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*don't...

## Client = HttpClient
## AsyncClient = AsyncHttpClient
##
## proc multisync_function(this: Client | AsyncClient): Future[string] {.multisync.} =
Copy link
Contributor

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
Copy link
Contributor

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()

@treeform
Copy link
Contributor

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:

  • asyncCheck - is like spawn in other languages - it starts a new async-thread and branches execution.
  • waitFor and await - are basically same thing, one you use inside async code the other one you use outside async code. If compiler complains just switch one to the other :)

Off-topic, but if it was up to me I would:

  • Rename asyncCheck -> spawn
  • Make await act like waitFor when outside {.async.} functions
  • Wrap result in a Future automatically when using {.async.}

@juancarlospaco
Copy link
Collaborator Author

...but it does wrap the result on a Future, even if you do not declare an explicit return it returns Future[void]. 🤔

@disruptek
Copy link
Contributor

return wraps its argument but result is always Future.

@treeform
Copy link
Contributor

treeform commented Jan 12, 2020 via email

@disruptek
Copy link
Contributor

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 return behaved as expected, instead.

@treeform
Copy link
Contributor

It is too late to change how {.async.} works now. Sorry for derailing the discussion. I think the docs are good.

@narimiran
Copy link
Member

This doesn't belong in the manual as it's not a language feature, it should probably be in a separate document

Maybe an async tutorial as well?

IMHO this should be an async tutorial and the asyncdispatch modules should link to the tutorial.

We all agree on that.

So, if we all agree on that, can we close this PR and use its content as a basis for doc/tut4.rst, which will be async tutorial?

@juancarlospaco
Copy link
Collaborator Author

Feel free to close if is the way forward.

@narimiran
Copy link
Member

Feel free to close if is the way forward.

I think it is. Now waiting for your async tutorial :)

@narimiran narimiran closed this Jan 23, 2020
@timotheecour timotheecour mentioned this pull request Mar 30, 2020
1 task
@ringabout
Copy link
Member

What's the progress of this tutorial?

@Araq Araq reopened this Nov 23, 2020
@Araq
Copy link
Member

Araq commented Nov 23, 2020

We don't have a tutorial so we should take the doc improvements. Please continue your work @juancarlospaco !

@ringabout
Copy link
Member

This also fixes #5021

@timotheecour timotheecour added the stale Staled PR/issues; remove the label after fixing them label Dec 12, 2020
@ringabout
Copy link
Member

Succeeded by #19738

@ringabout ringabout removed the stale Staled PR/issues; remove the label after fixing them label May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants