coro icon indicating copy to clipboard operation
coro copied to clipboard

`on.exit()` only called when iterator is exhausted

Open hadley opened this issue 1 year ago • 0 comments

g <- coro::generator(function() {
  on.exit(cat("** on.exit called\n"))
  yield(1)
  yield(2)
})

coro::loop(for (i in g()) {
})
#> ** on.exit called

coro::loop(for (i in g()) {
  stop("boom!")
})
#> Error in eval_bare(loop, env): boom!

coro::loop(for (i in g()) {
  break
})

Created on 2024-09-11 with reprex v2.1.0

hadley avatar Sep 11 '24 12:09 hadley