This isn't something I expected to get hung up on but for the life of me I can't think of a simple solution.
For normal file i.o. as per the docs:
var f: File
if f.open(filepath, filemode):
try:
...
except:
...
finally:
f.close()
Which works great. However this is not possible with an async file. Thus my basic issue is I cannot tell if the file opened successfully or not so I cant call file.close() reliably without getting a segfault if the file failed to open.
e.g. bad code
var file: AsyncFile
try:
file = openasync(filepath, filemode)
except:
...
finally:
file.close()
Untested but what about:
var file: AsyncFile
var success = false
try:
file = openasync(filepath, filemode)
success = true
except:
...
finally:
if success:
file.close()
(We could fix the module so that close succeeds regardless.)