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 Io / Tokio Support #436

Open
DrSloth opened this issue May 22, 2021 · 4 comments
Open

Async Io / Tokio Support #436

DrSloth opened this issue May 22, 2021 · 4 comments
Milestone

Comments

@DrSloth
Copy link

DrSloth commented May 22, 2021

Hi,
I am currently working on an async IoT web app and use this crate. I often have changes in templates / user defined templates
and often have to reload them. Currently, all io, such as reading and writing to disk, can only be implemented blocking from what I have seen.
Is async IO / support for Tokio planned, would you accept a PR for simple async IO if it is behind a feature flag?
Or is there a way to implement async rendering / writing that I am missing?

Thanks in advance and keep up the good work!

@sunng87
Copy link
Owner

sunng87 commented May 22, 2021

Yes, a PR for async is welcomed. Please create it against our latest master branch because 4.0 has a new concept called TemplateSource. Let me know if you need help with the PR.

@sunng87 sunng87 added this to the 4.1 milestone May 23, 2021
@DrSloth
Copy link
Author

DrSloth commented May 25, 2021

Sorry for the late answer. I am going to work on this as soon as i have time. I am going to comment here again if any questions arise.

@DrSloth
Copy link
Author

DrSloth commented Dec 22, 2021

Hello. I am sorry i forgot about this for some while and revisited it last weekend.
I couldn't find a way where async is really benficial here, as far as i can see the compiler is not really made for "streaming" parsing and compiling. Compiling a template is obviously cpu bound and for some benefit the compiler would need to handle "steams" of data rather than directly parsing a string.
The read can be made async by directly using the functions which parse from string and using something like tokio::fs::read_to_string. Maybe i am missing something but i don't know how this could be generically added while also yielding real benefit without rewriting large parts of the parser/compiler logic.

Maybe someone else has an idea where async is beneficial and they, me or we can take a look at it again.

@sunng87 sunng87 modified the milestones: 4.2, 5.0 Jan 1, 2022
@Diegovsky
Copy link

You would have to rewrite the parser to work with streams. Maybe using a buffer so it can go back a few bytes or forwards while parsing. I unfortunately don't have much time (and expertise) otherwise I would open a PR :(

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

No branches or pull requests

3 participants