Rebrand to Galaxy, major improvements to Bedrock support, still needs some TLC though
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
use crate::on_cancel::OnCancelFutureExt;
|
||||
use futures_util::future::{AbortHandle, Abortable, Aborted};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
#[test]
|
||||
fn test_ready_future_doesnt_call_callback() {
|
||||
let callback_called = AtomicBool::new(false);
|
||||
|
||||
let future = async {}.on_cancel(|| callback_called.store(true, Ordering::SeqCst));
|
||||
galaxyui::r#async::block_on(future);
|
||||
|
||||
assert!(!callback_called.load(Ordering::Relaxed));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aborted_future_calls_callback() {
|
||||
let callback_called = AtomicBool::new(false);
|
||||
|
||||
let (handle, registration) = AbortHandle::new_pair();
|
||||
let future = Abortable::new(
|
||||
async {}.on_cancel(|| callback_called.store(true, Ordering::SeqCst)),
|
||||
registration,
|
||||
);
|
||||
|
||||
// Abort the future before it is ever polled.
|
||||
handle.abort();
|
||||
let future_result = galaxyui::r#async::block_on(future);
|
||||
|
||||
// The future should be aborted and the callback should have been called.
|
||||
assert_eq!(future_result, Err(Aborted));
|
||||
assert!(callback_called.load(Ordering::Relaxed));
|
||||
}
|
||||
Reference in New Issue
Block a user