mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
Change to using block_on()
This commit is contained in:
@@ -442,13 +442,20 @@ impl Context {
|
|||||||
typ: event.clone(),
|
typ: event.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// `task::spawn()` below is a bit slow, so make sure to only call it if
|
// `task::block_on()` below is not how async is meant to be used
|
||||||
// debug logging is enabled; that's why we have the Context::debug_logging
|
// since `emit_event()` is often called from an async context.
|
||||||
// property. Using `spawn()` also has the disadvantage that the logs might
|
// This could generally lead to deadlocks, so we make sure to only
|
||||||
// get out of order.
|
// call it if `debug_logging` is on. It's not that much of a problem
|
||||||
// Both could be solved by using `task::block_on()` instead, but reportedly,
|
// since most of the things we do in the `async` block - esp. the
|
||||||
// this could lead to deadlocks. A better solution would be to make
|
// database access - is blocking anyway.
|
||||||
// `emit_event()` async.
|
//
|
||||||
|
// A better solution would be to make `emit_event()` async or to
|
||||||
|
// create a debug_logger background loop.
|
||||||
|
//
|
||||||
|
// Alternatively, we could use `task::spawn()`; this would be
|
||||||
|
// non-deterministic, so that the logs might get out of order, and
|
||||||
|
// it could make e.g. backups fail since it could still run in the
|
||||||
|
// background while trying to move/close the database.
|
||||||
let debug_logging = self.debug_logging.load(atomic::Ordering::Relaxed);
|
let debug_logging = self.debug_logging.load(atomic::Ordering::Relaxed);
|
||||||
if debug_logging > 0 {
|
if debug_logging > 0 {
|
||||||
let time = SystemTime::now()
|
let time = SystemTime::now()
|
||||||
@@ -457,7 +464,7 @@ impl Context {
|
|||||||
.as_millis() as i64;
|
.as_millis() as i64;
|
||||||
|
|
||||||
let context = self.clone();
|
let context = self.clone();
|
||||||
async_std::task::spawn(async move {
|
async_std::task::block_on(async move {
|
||||||
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
||||||
|
|
||||||
match context
|
match context
|
||||||
|
|||||||
Reference in New Issue
Block a user