Skip to content

Instantly share code, notes, and snippets.

View envis10n's full-sized avatar

Andrew envis10n

View GitHub Profile

Keybase proof

I hereby claim:

  • I am envis10n on github.
  • I am envis10n (https://keybase.io/envis10n) on keybase.
  • I have a public key whose fingerprint is 4A39 35AB 5C4C 15F7 1025 25B7 C9A9 5169 7A8D B7A2

To claim this, I am signing this object:

function wrap(value: number, max: number, min: number): number {
while (value > max || value < min) {
value = value > max ? value - (max + 1) : value < min ? value + (max + 1) : value;
}
return value;
}
function wrap_u8(value: number = 0): number {
return wrap(value, 255, 0);
}
@envis10n
envis10n / main.rs
Created February 11, 2019 22:18
Event loop in Rust using Tokio, futures, and mpsc channels.
type Closure = Box<Fn() + Send>;
fn main() {
let (tx, rx) = std::sync::mpsc::channel::<Closure>();
let eventloop = futures::future::lazy(move || {
loop {
if let Ok(call) = rx.recv() {
tokio::spawn(futures::future::lazy(move || {
call();
futures::future::ok::<(), ()>(())