Skip to content

Commit 478f717

Browse files
Move async example to asynchronous version of proc (#18078)
* improve runnableExamples in std/httpclient * Add synchronous example. * Update lib/pure/httpclient.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
1 parent d217888 commit 478f717

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/pure/httpclient.nim

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,11 @@ proc newHttpClient*(userAgent = defUserAgent, maxRedirects = 5,
574574
##
575575
## `headers` specifies the HTTP Headers.
576576
runnableExamples:
577-
import std/[asyncdispatch, httpclient, strutils]
577+
import std/strutils
578578

579-
proc asyncProc(): Future[string] {.async.} =
580-
var client = newAsyncHttpClient()
581-
return await client.getContent("http://example.com")
582-
583-
let exampleHtml = waitFor asyncProc()
579+
let exampleHtml = newHttpClient().getContent("http://example.com")
584580
assert "Example Domain" in exampleHtml
585-
assert not ("Pizza" in exampleHtml)
581+
assert "Pizza" notin exampleHtml
586582

587583
new result
588584
result.headers = headers
@@ -616,6 +612,17 @@ proc newAsyncHttpClient*(userAgent = defUserAgent, maxRedirects = 5,
616612
## connections.
617613
##
618614
## `headers` specifies the HTTP Headers.
615+
runnableExamples:
616+
import std/[asyncdispatch, strutils]
617+
618+
proc asyncProc(): Future[string] {.async.} =
619+
let client = newAsyncHttpClient()
620+
result = await client.getContent("http://example.com")
621+
622+
let exampleHtml = waitFor asyncProc()
623+
assert "Example Domain" in exampleHtml
624+
assert "Pizza" notin exampleHtml
625+
619626
new result
620627
result.headers = headers
621628
result.userAgent = userAgent

0 commit comments

Comments
 (0)