-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: Add support for async loading using either futures
or tokio
AsyncRead traits
#69
Conversation
Remove duplicated code between load_obj_buf() and load_obj_buf_async(), by refactoring out the majority of logic to helper structs. Now, only the async-specific logic is different in load_obj_buf_async(), which should significantly help in preventing it from bitrotting.
In order to allow proper async loading of objs and materials, the reader needs to be async itself. Unfortunately there are no standard async read/write traits, so the best solution is to implement per-framework async functions for the known big frameworks, gated behind feature flags. This commit adds support for `futures` AsyncRead traits.
In order to allow proper async loading of objs and materials, the reader needs to be async itself. Unfortunately there are no standard async read/write traits, so the best solution is to implement per-framework async functions for the known big frameworks, gated behind feature flags. This commit adds support for `tokio` AsyncRead traits.
Add the missing `async` dependency to futures/tokio features, so they also pull in the relevant async bits. Also do a slight rename to fix a warning for building with only the `futures` feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @debroejm I think this looks good! We can just mark the old async API deprecated and then this is good to
The original load_obj_buf_async() function is not properly async, since it doesn't use async readers. Deprecate this function and point to the new ones.
Added the deprecation. Hmm, there is theoretical performance improvement in the async path, where loading materials is delayed until after the entire OBJ buffer is read, and then all materials can be asynchronously loaded at the same time (instead of one at a time while reading the OBJ buffer), but this would only really matter for an OBJ with a quite large count of separate material buffers, and would require a significant change in logic to delay the material loading. Probably something that can be added in the future if deemed necessary. |
Fixes #68
Implements AsyncRead trait support for specifically
futures
andtokio
. Other frameworks can of course be added as needed.