followup #16871 asyncjs.then: allow pipelining procs returning futures#17189
Merged
Araq merged 15 commits intonim-lang:develfrom Mar 4, 2021
Merged
followup #16871 asyncjs.then: allow pipelining procs returning futures#17189Araq merged 15 commits intonim-lang:develfrom
Araq merged 15 commits intonim-lang:develfrom
Conversation
Merged
ringabout
reviewed
Feb 26, 2021
12ac0fe to
006b55b
Compare
Member
Author
|
ping @Araq after this PR, # funs.nim
from std/jsffi import JsObject
import std/[jsfetch,asyncjs,sugar,jsconsole]
proc main {.async.} =
await fetch("https://api.github.com/users/manishmshiva".cstring)
.then((response: Response) => response.json())
.then((json: JsObject) => console.log(json))
.catch((err: Error) => console.log("Request Failed", err))
await fetch("https://D20210227T115923_bad_url".cstring)
.then((response: Response) => response.json())
.then((json: JsObject) => console.log(json))
.catch((err: Error) => console.log("Request Failed from nim", err))
discard main()which allows easy port from js code like this https://www.freecodecamp.org/news/javascript-fetch-api-tutorial-with-js-fetch-post-and-header-examples/ // GET Request.
fetch('https://api.github.com/users/manishmshiva')
// Handle success
.then(response => response.json()) // convert to json
.then(json => console.log(json)) //print data to console
.catch(err => console.log('Request Failed', err)); // Catch errorsin a broswer, the following html: [1] I had to modify #12531 as follows /cc @juancarlospaco |
Collaborator
|
It is a relevant change, therefore needs another line on the changelog. IMHO. |
Member
Author
|
I think it's already covered by the existing one: |
Merged
ringabout
approved these changes
Mar 3, 2021
6eb67e1 to
bb26bd1
Compare
ringabout
pushed a commit
to ringabout/Nim
that referenced
this pull request
Mar 22, 2021
…g futures (nim-lang#17189) * followup nim-lang#16871 asyncjs.then: allow pipelining procs returning futures * rename test files where they belong * fix tests * tests for then with `onReject` callback * rename test file containing fail to avoid messing with grep * address comments * cleanup * un-disable 1 test
ardek66
pushed a commit
to ardek66/Nim
that referenced
this pull request
Mar 26, 2021
…g futures (nim-lang#17189) * followup nim-lang#16871 asyncjs.then: allow pipelining procs returning futures * rename test files where they belong * fix tests * tests for then with `onReject` callback * rename test file containing fail to avoid messing with grep * address comments * cleanup * un-disable 1 test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

followup #16871
thennow allows pipelining futures (instead of just callbacks), and we avoid returningFuture[Future[T]]which would be wrong (would break the monadic property that allows pipeliningonRejectcallback is now testedtypeOrVoid(which I'll expose in typetraits in future work)future work
typeOrVoidor maketypeof(someProcReturningVoid()) is voidworknimExperimentalAsyncjsThenflag once stabilized