-
-
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
followup #16871 asyncjs.then: allow pipelining procs returning futures #17189
followup #16871 asyncjs.then: allow pipelining procs returning futures #17189
Conversation
12ac0fe
to
006b55b
Compare
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 errors in a broswer, the following html:
[1] I had to modify #12531 as follows /cc @juancarlospaco
|
It is a relevant change, therefore needs another line on the changelog. IMHO. |
I think it's already covered by the existing one:
|
6eb67e1
to
bb26bd1
Compare
…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
…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
followup #16871
then
now allows pipelining futures (instead of just callbacks), and we avoid returningFuture[Future[T]]
which would be wrong (would break the monadic property that allows pipeliningonReject
callback is now testedtypeOrVoid
(which I'll expose in typetraits in future work)future work
typeOrVoid
or maketypeof(someProcReturningVoid()) is void
worknimExperimentalAsyncjsThen
flag once stabilized