Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async filesystem access #89

Open
senekor opened this issue Jun 19, 2023 · 0 comments
Open

async filesystem access #89

senekor opened this issue Jun 19, 2023 · 0 comments
Assignees

Comments

@senekor
Copy link
Owner

senekor commented Jun 19, 2023

context

The webserver framework we are using is asynchronous. That means request handlers may be stopped and have to wait while other handlers continue their work. This leads to better performance, because while one handler is waiting for some IO operation like networking or access to the filesystem, another handler may do useful work in the meantime.

You may have noticed the keywords asnyc and await in the code base. An asnyc function can be stopped and wait for some other thing, while other tasks make progress. The await keyword is used to await the completion of such a task, like networking or filesystem access.

what to do

Even though we're technically using async, our filesystem access is using the blocking1 functions from std. Our async runtime tokio has its own functions for accessing the filesystem in an asynchronous manner. Unlike the blocking operations from std, the return values of such asynchronous filesystem operations need to be awaited with .await. See the documentation of tokio for examples.

Replace the use of std::fs with tokio::fs.

Footnotes

  1. "blocking" is the opposite of "async". When a blocking operation is waiting for something, like the filesystem, other tasks are blocked from making progress. We don't want that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants