release session stream after close

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-02-15 20:39:30 +08:00
parent 6e12e77f51
commit d5502f58ef
2 changed files with 6 additions and 0 deletions

View File

@ -1368,6 +1368,9 @@ class FFI {
// Preserved for the rgba data.
await for (final message in stream) {
if (message is EventToUI_Event) {
if (message.field0 == "close") {
break;
}
try {
Map<String, dynamic> event = json.decode(message.field0);
await cb(event);

View File

@ -132,6 +132,9 @@ pub fn session_login(id: String, password: String, remember: bool) {
pub fn session_close(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
if let Some(stream) = &*session.event_stream.read().unwrap() {
stream.add(EventToUI::Event("close".to_owned()));
}
session.close();
}
let _ = SESSIONS.write().unwrap().remove(&id);