Markdown code blocks migration part 7 (#20547)

This commit is contained in:
Andrey Makarov 2022-10-12 17:13:43 +03:00 • committed by GitHub
commit 19ff746916
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 426 additions and 411 deletions

View file

@ -17,37 +17,42 @@
##
## This is roughly equivalent to the `async` keyword in JavaScript code.
##
## .. code-block:: nim
## proc loadGame(name: string): Future[Game] {.async.} =
## # code
## ```nim
## proc loadGame(name: string): Future[Game] {.async.} =
## # code
## ```
##
## should be equivalent to
##
## .. code-block:: javascript
## ```javascript
## async function loadGame(name) {
## // code
## }
## ```
##
## A call to an asynchronous procedure usually needs `await` to wait for
## the completion of the `Future`.
##
## .. code-block:: nim
## ```nim
## var game = await loadGame(name)
## ```
##
## Often, you might work with callback-based API-s. You can wrap them with
## asynchronous procedures using promises and `newPromise`:
##
## .. code-block:: nim
## ```nim
## proc loadGame(name: string): Future[Game] =
## var promise = newPromise() do (resolve: proc(response: Game)):
## cbBasedLoadGame(name) do (game: Game):
## resolve(game)
## return promise
## ```
##
## Forward definitions work properly, you just need to always add the `{.async.}` pragma:
##
## .. code-block:: nim
## ```nim
## proc loadGame(name: string): Future[Game] {.async.}
## ```
##
## JavaScript compatibility
## ========================
@ -57,7 +62,7 @@
## If you need to use this module with older versions of JavaScript, you can
## use a tool that backports the resulting JavaScript code, as babel.
# xxx code-block:: javascript above gives `LanguageXNotSupported` warning.
# xxx code: javascript above gives `LanguageXNotSupported` warning.
when not defined(js) and not defined(nimsuggest):
{.fatal: "Module asyncjs is designed to be used with the JavaScript backend.".}