The runtime-loop crate provides a common runtime loop that continuously attempts to find changes in your system, and act upon them accordingly.
extern crate runtime_loop; use ; use thread; use ; use Ordering; use time; // Create memory for the runtime loop. Grab the cancel flag to exit the loop based on time. let mut rloop = new; let cancel_flag = rloop.get_cancel_flag; // When polled, increment the value. // This should normally be your poll function. We increment x as a test. let target = new; // When the polled value changes, print a message. if let Ok = target.lock // Add the pollable to the runtime loop. rloop.add_pollable; // This is an async runtime loop. Though it is acceptable to call rloop.run() without spawning a new thread, spawning a new thread will enable external cancellation of the runtime loop. let runtime_thread = spawn; // Run for N milliseconds before canceling and joining threads. sleep; //let the thread run for a bit cancel_flag.store; //Cancel runtime loop! if let ResultErr = runtime_thread.join
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.