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
Usage of the Send
trait in cursive
#383
Comments
I've been trying to avoid requiring I'm tempted by option 2) where we have a separate queue for non- Also possibly interesting: https://crates.io/crates/send_wrapper |
I agree, I will look into the Thanks for you're quick reply and awesome project you are running here! 😎 |
I got a POC running with the Is there a better way to enqueue callbacks delayed into cursive? |
I haven't thought about delayed callbacks much yet, but it looks like a good solution so far. Though it now means that the callback is executed in the same thread, and is responsible for doing async request? I guess one option may be to split async process and view creation: fn run_async<Callback, R, ViewMaker, V>(callback: Callback, view_maker: ViewMaker)
where Callback: Send + FnOnce() -> R,
R: Send,
ViewMaker: FnOnce(R) -> V,
V: View,
{ /* ... */ }
run_async(|| slow_download().parse(), MyView::new); |
I decided against moving a callback into a dedicated thread as some operations like looking for a timeout, waiting for data on a channel, reading a file, etc. can be done "non-blocking" by using methods like The user can decide whether a dedicated thread is needed. The I will create another example which shows how to use the Concerning the 3 possibilities mentioned above, I would suggest leaving the API as is. A comment in the documentation of the /cc @jwuensche |
Added a comment in the doc. |
I would like to discuss the usage of the
Send
trait in theCbSink
andView
implementations.Problem description
I am currently working on a reimplementation of the
cursive-async-view
crate on thefeature/no-more-threads-for-you
branch.The implementation on the
master
branch currently requires the async loaded view to beSend
. This is not the case for many cursive views like theSelectView
,EditView
,Button
,LinearLayout
,ListView
, etc. In order for theAsyncView
to be useful, we have to remove theSend
restriction for the async loaded view.A solution would be to use the cursive event loop to regularly check for the async loaded view to be available. However, the cursive event loop requires the callback sent into the
CbSink
to beSend
. This restriction is only needed when the user of a cursive instance wants to use theCbSink
in another thread. Cursive itself does not need the callback to beSend
as the event loop implementation is completely single-threaded.In order to allow async creation of views (and usage of views in a
CbSink
callback) we need to do one of the following:Send
restriction from theCbSink
. This will break all code which uses theCbSink
in another thread (like many of the provided examples).CbSink
which does not require the callback to beSend
. Meaning, there would beCbSendSink = Sender<Box<dyn FnOnce(&mut Cursive) + Send>>
and aCbSink = pub type CbSink = Sender<Box<dyn FnOnce(&mut Cursive)>>
, whereCbSendSink
would be usable like the currentCbSink
and the newCbSink
would be usable from within the cursive thread (e.g. via another callback).View
trait require a view to beSend
. This might have performance impacts as types likeRc
andRefCell
cannot be used any more. Also, many existing views must be reimplemented to match the newSend
requirement, which may introduce new bugs and backward compatibility problems.Do you have any other ideas or suggestions on how to resolve this problem?
/cc @jwuensche
The text was updated successfully, but these errors were encountered: