1use core::time::Duration;
8use dispatch::{Queue, QueuePriority};
9
10use crate::{PlatformExecutor, Priority};
11
12impl From<Priority> for QueuePriority {
13 fn from(val: Priority) -> Self {
14 match val {
15 Priority::Background => Self::Background,
16 Priority::Utility => Self::Low,
17 Priority::UserInitiated | Priority::UserInteractive => Self::High,
18 _ => Self::Default,
20 }
21 }
22}
23#[derive(Debug, Clone, Copy, Default)]
28pub struct ApplePlatformExecutor;
29
30impl PlatformExecutor for ApplePlatformExecutor {
31 fn exec_main(f: impl FnOnce() + Send + 'static) {
32 let main = Queue::main();
33 main.exec_async(f);
34 }
35
36 fn exec(f: impl FnOnce() + Send + 'static, priority: Priority) {
37 let queue = Queue::global(priority.into());
38 queue.exec_async(f);
39 }
40
41 fn exec_after(delay: Duration, f: impl FnOnce() + Send + 'static, priority: Priority) {
42 let queue = Queue::global(priority.into());
43 queue.exec_after(delay, f);
44 }
45}