-
Notifications
You must be signed in to change notification settings - Fork 307
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
Long-lived Rust code that sends data continuously back to Dart #347
Comments
No. It is not the case. I guess just use the StreamSink is enough. B/c my own use case for StreamSink is as follows. I use it for logging purpose.
|
This is how I imagine a long-running Rust function would look like: in this gist, I did uncover new questions and problems with this example however:
|
@Desdaemon Thanks for the sample!
I agree.
Agree as well ;) |
Doc updated. Now https://fzyzcjy.github.io/flutter_rust_bridge/feature/stream.html has an example of logger, and an example copied from @Desdaemon 's gist. |
Hey guys, thanks for the replies. Super exhausted and will review in the morning. I should have time to work on the benchmarks tomorrow as well. Cheers |
Thanks for the Gist @Desdaemon. Having the StreamSink go out of scope on the Dart side is certainly an issue - not just with a long-lived Rust process, but in theory, it could happen with a short-lived execution as well. This is definitely a hole that needs to be fixed. Is there any way to send data to Rust from Dart? The StreamSinks are one direction, no? This feels like a scenario where some sort of context could be useful. For example, the Rust side could check if a context is still valid before writing to the StreamSink. OR I have a lot of experience with Go. In Go, we have When I was learning Rust, I cloned one of our Go projects using Tokio. Using Tokio and Tokio's MPSC/Oneshot channels in conjunction with Tokio's select blocks, I was able to create a perfect clone. https://tokio.rs/tokio/tutorial/select Based on what I know so far about FRB, I feel like @Desdaemon's example could be expanded so that Again, not sure if something like this could actually work, but it's an idea. |
I really like this idea! It would be awesome to see a snippet of this in action.
Dart has its own StreamSink, perhaps we can use it or at least the idea? |
What about directly calling a rust function? And in that rust function do anything you like, such as enqueueing the data to a Vec, use an Iterator, a Stream etc.
Sounds interesting! |
Can we do something like this: When the
|
What happens when the Dart side closes (terminates an isolate waiting on a sink) the StreamSink but the Rust side is still running, as @Desdaemon has pointed out? It's entirely possible for the Rust side to add data to a StreamSink that is no longer valid. |
I feel like this was closed, far from any reasonable solution/resolution being reached. |
The |
Maybe no problem? Dart cannot close the stream. Only Rust triggers closing. Btw, why dart create isolates? in my use case everything is on main isolate
Agree. Btw that means whether the data send to SendPort gets sent successfully, not about whether the stream is closed or not... Anyway error handling is hard... |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue. |
Hey Guys,
I thought I'd start a new thread for the question that I did not get an adequate answer to.
Here is a scenario. A Flutter/Dart app needs to start a Rust layer that runs for the life of the application. The Rust layer creates a TCP connection with a remote server and maintains the connection for the life of the app being opened.
The Rust layer needs to stream data back to the Flutter/Dart layer.
The current StreamSink design involves making a call to Rust via the FFI, doing some type of work, streaming the data back Dart/Flutter and once the function call has completed, the Rust layer closes.
Would it be possible to start a Rust layer, have it run for the life of an application, streaming data back to a Dart/Flutter layer? Something like a channel?
The text was updated successfully, but these errors were encountered: