WriteAll to filestream async

Monkey Forums/Monkey Beginners/WriteAll to filestream async

Trion(Posted 2016) [#1]
Hello! Is here any possibility to write data to file asynchronously?
I am writing a little server using tcpasync. It works fine, but I dont want to break main loop on saving some data to server's hdd. What can you suggest?


Pharmhaus(Posted 2016) [#2]
Here is a working example I just wrote for you:



Pharmhaus(Posted 2016) [#3]
There are a few things to note:
Monkeys Garbage Collector does not like creating object (no new XYZ, strings work when using StrDup) on a different thread than the mainthread.
Also, all methods that the are called by the thread need to end with __UNSAFE__ or need to be defined as extern.
The class you see at the bottom is just in copy of the regular filestream with the name of write changed to unsafe.


Trion(Posted 2016) [#4]
Wow! Thank you! Very nice stuff!