-
Notifications
You must be signed in to change notification settings - Fork 83
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
Rewriter reuse example? #82
Comments
Hmm, this seems to work fine as-is - I ran |
The issue is when a user might want to define the rewriting rules on one thread and use them on another (or several others) — because even the rule definitions are !Send, it's unclear how to use this crate in a multithreaded context, or even a An example. The workaround I ended up settling on was to have the user provide a It's also worth noting that at the time of filing this, #69 had not yet been released |
It's true that |
Oh hmm, I missed that |
@jbr hmm, I'm confused though - how would it be useful to share the rewriter between threads? How would you synchronize writing the input so you know the output makes sense? |
There are a few distinct concerns here, and I'm not entirely sure that any of them are specific suggestions or feature requests for any multithreaded applicationA user defines 'static Settings on one thread and hands it to a library, which then is able to send the Settings or clones of the Settings to other threads or an Arc of the settings to other threads, which can then use those same settings in their own rewriters. The simplest version of this would create a new rewriter for each http request and drop it at the end of rewriting. Depending on how cheap creating rewriters is, it might make sense to use some sort of rewriter pool, either thread-locally or shared. This seems relevant to sync rust as well as async. async use specificallyIdeally the rewriters would also be Send but I imagine that introduces unacceptable performance costs to the other users of this crate. The motivation behind the Send bound is that use with most of the async ecosystem requires being able to move a Future that contains the rewriter between work-sharing executor threads. Most async runtimes (tokio, smol, async-std) also offer local (non-work-sharing) executors, which is how |
Ah, so for rewriters you actually only need them to be Send, not Sync? |
I'm trying to understand how and if users are intended to express a set of element handlers to be reused on multiple inputs, across multiple threads. In particular, I'm interested in applying a given transformation to a bunch of html byte streams, but the lifetimes and borrows in the public interface make it difficult to see how to achieve that. Is there example code out there, or a part of the documentation that's relevant to this usage pattern?
Thanks!
The text was updated successfully, but these errors were encountered: