GithubHelp home page GithubHelp logo

chrismacnaughton / rdispatcher Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timonv/rdispatcher

0.0 2.0 0.0 156 KB

Dispatcher for Rust, broadcast and subscribe many to many

Rust 100.00%

rdispatcher's Introduction

Rust Dispatcher

The Dispatcher allows you to send messages from multiple broadcasters to multiple receivers. When a lot of messages get passed around a threaded application, centralizing where messages flow through can create much wanted oversight.

The types of messages that get passed around are strongly typed, required by you to setup, and the messages themselves are strings.

Install

Add to your Cargo.toml

rdispatcher = "*"

And run cargo install

Usage

A simple example:

  let mut dispatcher = Dispatcher::new();
  let sub = TestSubscriber::new();
  let mut brd = TestBroadcaster::new();
  dispatcher.register_broadcaster(&mut brd);
  dispatcher.register_subscriber(&sub, OutgoingMessage);

  dispatcher.start();

  brd.broadcast(OutgoingMessage, "Hello world!".to_string());
  let message = sub.receiver.recv().unwrap();
  assert_eq!(message.dispatch_type, OutgoingMessage);
  assert_eq!(message.payload, "Hello world!");

For several full examples, checkout the tests in lib.rs

Caveats

  • Currently the DispatchType (I prefer using an enum for it) is cast to a string using Debug. This is legacy and should just use Hash. If you have a custom Debug for your your enum, you might get unexpected results. Resolved
  • Complex enums (i.e. SomethingComplex(String)) currently do not work as the dispatch type and will yield weird results.

rdispatcher's People

Contributors

timonv avatar

Watchers

James Cloos avatar  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.