File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,21 @@ impl eframe::App for BrowseApp {
58
58
fn update ( & mut self , ctx : & egui:: Context , _frame : & mut eframe:: Frame ) {
59
59
// assign sample text once it comes in
60
60
if let Some ( promise) = & self . promise {
61
- if let Some ( result) = promise. ready ( ) {
62
- if let Some ( text) = result {
63
- self . sample_text = text. clone ( ) ;
61
+ if promise. ready ( ) . is_some ( ) {
62
+ // Clear promise and take the value out
63
+ // Doesn't matter for string as we can just clone it but depending on the type you have
64
+ // you may not be able to easily clone it and would prefer get the owned value
65
+ let mut temp = None ;
66
+ std:: mem:: swap ( & mut temp, & mut self . promise ) ;
67
+
68
+ let owned_promise = temp. expect ( "we got here because it was some" ) ;
69
+ let inner_option = owned_promise. block_and_take ( ) ; // This should be fine because we know it's ready
70
+
71
+ if let Some ( text) = inner_option {
72
+ self . sample_text = text;
64
73
} else {
65
74
// User probably cancelled or it was saving but the promise completed either way
66
75
}
67
- // Clear promise after we use it
68
- self . promise = None ;
69
76
}
70
77
}
71
78
You can’t perform that action at this time.
0 commit comments