Giter Site home page Giter Site logo

either-slot's Introduction

Either Slot

An atomic slot whose senders can either place their value into the slot, or retrive all the data from the slot.

Firstly we have the primary implmentation - [either], which have 2 senders attempting to send their own data into the slot. If one succeeds, the other will instead receive the data from the other sender alongside its own data. If one sender drops before the other sender sends, the latter will retrive back its own data only; but if the former drops after the latter, the data sent by the latter will be discarded.

Beside the primary implmentation, we also extend it to array slots and tuple slots, which resides in [mod@array] and [mod@tuple] module respectively.

Examples

The primary implementation

// Both ends attempt to send their data, but only one succeeds.
use either_slot::{either, SendError};

let (a, b) = either();
a.send(1).unwrap();
assert_eq!(b.send('x'), Err(SendError::Received('x', 1)));
// both ends cannot be used any longer after access.
// let _ = (a, b);
// If one end is dropped, the other end fails to send its data and retrives
// it back.
use either_slot::{either, SendError};

let (a, b) = either::<u8, _>();
drop(a);
assert_eq!(b.send(1), Err(SendError::Disconnected(1)));

The advanced implementation

Check the documenetation in [fn@array] and [fn@tuple] to see the corresponding examples.

License

MIT OR Apache-2.0

either-slot's People

Contributors

js2xxx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.