Replies: 2 comments
-
Since the resumption escapes the handler you should probably use fun main()
var cont := Nothing
val _ =
with handler
raw ctl op1()
cont := Just(fn() rcontext.resume(()))
()
test()
match cont
Just(res) ->
println("Calling continuation")
res()
Nothing -> () Output:
The explanation is that when you capture a resumption, there is no guarantee that the finalizers will ever run - if you never call resume. So at a high level the default behavior is to run finalizers after the operation finishes if there is no call to resume. For example, you want to close a file even if there is an exception thrown when working with the file. |
Beta Was this translation helpful? Give feedback.
-
Some related questions: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is probably a documentation issue, but the book section 3.4.11 says this about
finally
:My understanding of this is if I enter a continuation one or zero times, it should work as expected. But actually even with entering it once you can run a finalizer twice:
Output:
Note that "After op1" is printed once (i.e. the continuation is called once), but "In finally" is printed twice.
Beta Was this translation helpful? Give feedback.
All reactions