status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/docs/chronos
Apache License 2.0
353 stars 51 forks source link

Unroll `defer`s and remove `break`s. #440

Closed cheatfate closed 1 year ago

arnetheduck commented 1 year ago

generally, I think #418 is a better general-purpose fix. The problem with defer and finally is that we don't run the iterator to completion so not all code is run - this is the same problem as below, without a closure iterator transformation:

iterator x(): int {.closure.} =
  yield 42
  echo "hello"

proc works() =
   var z = x
   for a in z():
     echo a

proc broken() =
  var z = x

  for a in z():
    echo a
    break

works()
broken()
cheatfate commented 1 year ago

So should i wait for #418 to become ready or we are looking for leaks right now?