signal: refactor Windows registrations to be lazy (#1001)

- Use `Handle::default` over `Handle::current` for consistent semantics
- Make all `windows::Event` constructors lazily invoke `global_init`
  so they can be safely constructed off-task
- Don't assume the reactor is alive and event registration will be done
  when calling `global_init`

Add windows regression tests. Unfortunately, Windows doesn't have a
reliable way of programmatically sending CTRL_C or CTRL_BREAK events
to a progress, so the tests can only exercise our internal machinery by
invoking the handler that we register with the OS

Fixes #999
This commit is contained in:
Ivan Petkov
2019-04-01 12:46:22 -07:00
committed by Carl Lerche
parent 6c9d8abba9
commit 91bb0f73f5
4 changed files with 121 additions and 53 deletions
+6 -1
View File
@@ -53,7 +53,12 @@ fn main() -> Result<(), Box<std::error::Error>> {
// Up until now, we haven't really DONE anything, just prepared
// now it's time to actually schedule, and thus execute, the stream
// on our event loop
tokio::runtime::current_thread::block_on_all(future)?;
// FIXME(1000): windows uses a global driver task which doesn't terminate
// on its own, so if we use block_on_all our application will never exit
//tokio::runtime::current_thread::block_on_all(future)?;
tokio::runtime::current_thread::Runtime::new()
.expect("failed to start runtime on current thread")
.block_on(future)?;
println!("Stream ended, quiting the program.");
Ok(())