4 releases

new 0.2.1 Dec 1, 2024
0.2.0 Nov 24, 2024
0.1.1 Aug 27, 2024
0.1.0 Jun 12, 2024

#1031 in Asynchronous

Download history 137/week @ 2024-08-24 14/week @ 2024-08-31 12/week @ 2024-09-14 19/week @ 2024-09-21 20/week @ 2024-09-28 2/week @ 2024-10-05 2/week @ 2024-11-16 129/week @ 2024-11-23 157/week @ 2024-11-30

289 downloads per month
Used in kbremap

MIT/Apache

27KB
453 lines

winmsg-executor

Crates.io Crates.io License docs.rs

Per-thread async Rust executor for Windows. Each task is backed by a message-only window. The executor thread runs the native Windows message loop, which dispatches wake messages to the task's window procedure, which polls the task future.

Features

  • Easy data sharing within a thread because Send or Sync is not required for the task future.
  • Runs multiple tasks on the same thread. Tasks can spawn new tasks and await the result.
  • Modal windows like menus do not block other tasks running on the same thread.
  • Helper code to implement window procedures with closures that can have state.

Alternative Backend: async-task

Selected by the backend-async-task cargo feature. Uses async-task's task abstraction instead of a window per task to store the future. Scheduling a task means posting its runnable to the thread's message queue (similar to windows-executor see below).

Comparison with similar crates

Both of the listed crates run one task/future per thread and expose only block_on(). Is block_on an executor?

windows-executor

  • Polls its future directly from the message loop.
  • Does not create a window at all: Wakers store the message loop's thread id and notifies it with PostThreadMessage().
  • Does not close the thread's message loop (no PostQuitMessage() call) when the task future returns.

windows-async-rs

  • Polls directly from the message loop even when receiving broadcast messages unrelated to the task.
  • Questionable use of unsafe code

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~11–18MB
~227K SLoC