2 ms·
> Now this call needs to write to a log, which is async due to a file write or so. Well, think about, without having a specific language in mind. There are mul
by valenterry 6y ago
> Now this call needs to write to a log, which is async due to a file write or so.
Well, think about, without having a specific language in mind. There are multiple ways you want everything to be executed:
1. The library should call your function and wait until both parsing and writing to the file is finished before executing any other action
2. The library should call your function and wait until both parsing and writing to the file is finished, but potentially execute other actions (e.g. other parsing for another request) in the meantime / in between.
3. The library should call your function and wait until parsing is finished but not wait until writing to the file is finished (which also means to disregard the filewrite result)
The only way to really control how things happen is to have the library be aware of potential concurrency and that is true for Rust as well. There is no other solution, except for "hacks" which, when used, will make it impossible to understand what a piece of code does, without reading _all_ the code. Similar to global mutable variables (because that is what it would be).
If you application is small or not so critical, then you might indeed get away with a hack, but I think the energy should be focussed on improving languages so that libraries can easily be rewritten to embrace concurrency, rather than allowing for more hacks.