Skip to content

Instantly share code, notes, and snippets.

@aleics
aleics / clone_stream.rs
Created January 8, 2021 06:55
Clone streams by using Bus
use bus::{Bus, BusReader};
use futures::task::{Context, Poll};
use futures::Stream;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
/// `SourceInner` contains the reference to the Bus. `SourceInner` is available to the
/// `Source` instance, as well as its connected `SourceNode`. The `inner` needs to be wrapped
/// around a `Mutex` so that it's possible to include new receivers, and around a `Arc` so that
/// the instance is cloneable, potentially from multiple threads.
@aleics
aleics / result.ts
Created February 4, 2021 17:51
Rust Result in Typescript 🦀
interface Cases<O, T, E, R> {
ok: (value: O) => T;
err: (value: E) => R;
}
export abstract class Result<O, E> {
public abstract isOk(): boolean;