Merge branch 'devel' into araq-misc
This commit is contained in:
commit
404de2f23e
13 changed files with 193 additions and 17 deletions
|
|
@ -676,8 +676,8 @@ template mapIt*(s, op: untyped): untyped =
|
|||
var it{.inject.}: type(items(s));
|
||||
op))
|
||||
var result: seq[outType]
|
||||
evalOnce(t, s)
|
||||
when compiles(t.len):
|
||||
when compiles(s.len):
|
||||
evalOnce(t, s)
|
||||
var i = 0
|
||||
result = newSeq[outType](t.len)
|
||||
for it {.inject.} in t:
|
||||
|
|
@ -685,7 +685,7 @@ template mapIt*(s, op: untyped): untyped =
|
|||
i += 1
|
||||
else:
|
||||
result = @[]
|
||||
for it {.inject.} in t:
|
||||
for it {.inject.} in s:
|
||||
result.add(op)
|
||||
result
|
||||
|
||||
|
|
@ -1071,5 +1071,10 @@ when isMainModule:
|
|||
proc foo(x: openArray[int]): seq[int] = x.mapIt(it + 1)
|
||||
doAssert foo([1,2,3]) == @[2,3,4]
|
||||
|
||||
block: # mapIt with invalid RHS for `let` (#8566)
|
||||
type X = enum
|
||||
A, B
|
||||
doAssert mapIt(X, $it) == @["A", "B"]
|
||||
|
||||
when not defined(testing):
|
||||
echo "Finished doc tests"
|
||||
|
|
|
|||
|
|
@ -807,6 +807,7 @@ type
|
|||
lastProgressReport: float
|
||||
when SocketType is AsyncSocket:
|
||||
bodyStream: FutureStream[string]
|
||||
parseBodyFut: Future[void]
|
||||
else:
|
||||
bodyStream: Stream
|
||||
getBody: bool ## When `false`, the body is never read in requestAux.
|
||||
|
|
@ -1066,10 +1067,14 @@ proc parseResponse(client: HttpClient | AsyncHttpClient,
|
|||
if getBody:
|
||||
when client is HttpClient:
|
||||
client.bodyStream = newStringStream()
|
||||
result.bodyStream = client.bodyStream
|
||||
parseBody(client, result.headers, result.version)
|
||||
else:
|
||||
client.bodyStream = newFutureStream[string]("parseResponse")
|
||||
await parseBody(client, result.headers, result.version)
|
||||
result.bodyStream = client.bodyStream
|
||||
result.bodyStream = client.bodyStream
|
||||
assert(client.parseBodyFut.isNil or client.parseBodyFut.finished)
|
||||
client.parseBodyFut = parseBody(client, result.headers, result.version)
|
||||
# do not wait here for the body request to complete
|
||||
|
||||
proc newConnection(client: HttpClient | AsyncHttpClient,
|
||||
url: Uri) {.multisync.} =
|
||||
|
|
@ -1159,6 +1164,12 @@ proc requestAux(client: HttpClient | AsyncHttpClient, url: string,
|
|||
# Helper that actually makes the request. Does not handle redirects.
|
||||
let requestUrl = parseUri(url)
|
||||
|
||||
when client is AsyncHttpClient:
|
||||
if not client.parseBodyFut.isNil:
|
||||
# let the current operation finish before making another request
|
||||
await client.parseBodyFut
|
||||
client.parseBodyFut = nil
|
||||
|
||||
await newConnection(client, requestUrl)
|
||||
|
||||
let effectiveHeaders = client.headers.override(headers)
|
||||
|
|
|
|||
|
|
@ -198,3 +198,41 @@ macro dump*(x: typed): untyped =
|
|||
let r = quote do:
|
||||
debugEcho `s`, " = ", `x`
|
||||
return r
|
||||
|
||||
# TODO: consider exporting this in macros.nim
|
||||
proc freshIdentNodes(ast: NimNode): NimNode =
|
||||
# Replace NimIdent and NimSym by a fresh ident node
|
||||
# see also https://github.com/nim-lang/Nim/pull/8531#issuecomment-410436458
|
||||
proc inspect(node: NimNode): NimNode =
|
||||
case node.kind:
|
||||
of nnkIdent, nnkSym:
|
||||
result = ident($node)
|
||||
of nnkEmpty, nnkLiterals:
|
||||
result = node
|
||||
else:
|
||||
result = node.kind.newTree()
|
||||
for child in node:
|
||||
result.add inspect(child)
|
||||
result = inspect(ast)
|
||||
|
||||
macro distinctBase*(T: typedesc): untyped =
|
||||
## reverses ``type T = distinct A``; works recursively.
|
||||
runnableExamples:
|
||||
type T = distinct int
|
||||
doAssert distinctBase(T) is int
|
||||
doAssert: not compiles(distinctBase(int))
|
||||
type T2 = distinct T
|
||||
doAssert distinctBase(T2) is int
|
||||
|
||||
let typeNode = getTypeImpl(T)
|
||||
expectKind(typeNode, nnkBracketExpr)
|
||||
if typeNode[0].typeKind != ntyTypeDesc:
|
||||
error "expected typeDesc, got " & $typeNode[0]
|
||||
var typeSym = typeNode[1]
|
||||
typeSym = getTypeImpl(typeSym)
|
||||
if typeSym.typeKind != ntyDistinct:
|
||||
error "type is not distinct"
|
||||
typeSym = typeSym[0]
|
||||
while typeSym.typeKind == ntyDistinct:
|
||||
typeSym = getTypeImpl(typeSym)[0]
|
||||
typeSym.freshIdentNodes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue