Skip to content

wilbertom/bichannels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bidirectional Channels

This library implements bidirectional channels in Rust. The language has primitives to do this with the channel function. channel() returns a (sender, receiver) pair which can communicate with each other using message passing. These channels are used to communicate through different tasks.

A limitation of this is that only one can send messages, and the other can only receive messages. Using Rust's primitives we can extend this behaviour to allow sending and receiving messages from both ends. We call these ends Endpoints.

Usage

extern crate bichannels;

fn main() {
    let bichannels::BiChannel{e1:e1, e2:e2} = bichannels::BiChannel::new();

    spawn(proc(){
      e2.send("Hello");
      let r = e2.recv();
      println!("Endpoint 2 got: {}", r);
    });

    println!("Endpoint 1 got: {}", e1.recv());
    e1.send("Oh, hai.");
}

Unstable

This library is unstable because channels themselves are unstable in Rust.

About

Rust Bidirectional channels

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages