Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xenoken/hermes
Powerful PubSub Messaging for Dart
https://github.com/xenoken/hermes
dart dartlang eventbus events messaging pubsub
Last synced: about 2 months ago
JSON representation
Powerful PubSub Messaging for Dart
- Host: GitHub
- URL: https://github.com/xenoken/hermes
- Owner: xenoken
- License: bsd-3-clause
- Created: 2019-07-01T17:49:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-01T15:33:16.000Z (over 5 years ago)
- Last Synced: 2024-04-26T12:27:30.903Z (8 months ago)
- Topics: dart, dartlang, eventbus, events, messaging, pubsub
- Language: Dart
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Messaging library for Dart. Nimble and efficient like the messenger of the Gods.
# What is it
Hermes is a simple but powerful way to send and receive messages across a Dart App.
For those who are experienced Publish/subscribe messaging and event subscriptions, Hermes's mechanism will look very familiar.
One cool thing about Hermes is the ability to setup a pub\sub architecture with only *two lines* of code.
Divine.Hermes encapsulates the idea of event or signal (concept found in other messaging or eventing systems)
with the loose concept of Message.You can send a message from any position in your code. Hermes handles the task of carrying the message to all recipients that
are waiting for the message.In the same way you can send a Message from anywhere, You are able to receive a message sent from anywhere too.
For Hermes any object can act as a Message. Primitives, Functions, Built-in Types, Custom Types...*Anything*.
Hermes doesn't have the concept of registration. Everything is handled transparently. The moment your code wants to fetch a message, it automatically registers itself to receive it.
## How to Use it
To send a message just call the _send_ function.
```dart
Hermes.send(message);
// or
Hermes.send(T message);
```To receive a message just call the _fetch_ function.
```dart
Hermes.fetch(message, (T message){ });
// or
Hermes.fetch(T message, (T message){ });
```Note that _fetch_ acts like a transparent registration mechanism: when You call _fetch_ the specified handler function will be called whenever a new message of type T arrives.
From version 3.0.0 _fetch_ returns a FetchOperation instance. this object can be used to 'unfetch' and release resources:
```dart
Hermes.unfetch(FetchOperation op);
```A simple usage example:
```dart
import 'package:hermes/hermes.dart';class Message {
final String content;
Message(this.content);
}main() {
// registers a callback that is called when the message is received.
var fetchOp = Hermes.fetch((Message message) {
print("Message received. it says: '${message.content}'");
});// send a message
Hermes.send(Message("Hello World!"));
// ... some code here...
// unfetch the message if not required anymore.
Hermes.unfetch(fetchOp);
}```
## Remarks
- _Hermes.send_ and _Hermes.fetch_ are synchronous functions, but the message handler can be async.
- _Hermes.unfetch_ is an async function.## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: http://www.github.com/xenoken/hermes/issues