Skip to content

DouglasDwyer/geese_pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

geese_pool

Crates.io Docs.rs

This crate provides the ability to pass messages between multiple Geese instances, which may exist in separate processes or even on separate computers. The crate functions by maintaining a ConnectionPool of channels to other instances, through which messages may be sent or received. Systems may send or receive messages by raising the appropriate geese_pool events.

This crate is completely protocol agnostic; it does not provide an implementation for networking Geese instances using any specific standard, like UDP or TCP. It is up to the consumer to provide both a means of message serialization and network transport.

The following is a brief example of how an event may be sent between two separate event systems. The example first creates two Geese contexts, and adds the ConnectionPool system to both. Then, it creates a channel pair across which events may be forwarded, and places one channel in each connection pool. Finally, the connection pool of b is notified to send an integer to a. When a is subsequently updated, a message event containing the same integer is raised in a's event system.

struct Receiver(i32);

impl Receiver {
    fn respond(&mut self, message: &geese_pool::on::Message<i32>) {
        self.0 = **message;
    }
}

impl GeeseSystem for Receiver {
    const EVENT_HANDLERS: EventHandlers<Self> = event_handlers()
        .with(Self::respond);
    
    fn new(_: GeeseContextHandle<Self>) -> Self {
        Self(0)
    }
}

let mut a = GeeseContext::default();
a.raise_event(geese::notify::AddSystem::new::<ConnectionPool>());
a.raise_event(geese::notify::AddSystem::new::<Receiver>());
a.flush_events();

let mut b = GeeseContext::default();
b.raise_event(geese::notify::AddSystem::new::<ConnectionPool>());
b.flush_events();

let (chan_a, chan_b) = LocalChannel::new_pair();
a.system::<ConnectionPool>().add_peer(Box::new(chan_a));
let handle_a = b.system::<ConnectionPool>().add_peer(Box::new(chan_b));

b.raise_event(geese_pool::notify::message(1, handle_a));
b.flush_events();

a.raise_event(geese_pool::notify::Update);
a.flush_events();

assert_eq!(1, a.system::<Receiver>().0);

Optional features

serde - Provides a PeerChannel implementation that serializes and deserializes its data, as this is required for most forms of interprocess communication.

About

Message-passing system for networking with Geese.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages