Skip to content

Commit

Permalink
Update readme for library changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperPaul123 committed Oct 31, 2020
1 parent cda1b69 commit 2ad8a77
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ eventbus

`eventbus` is a simple, header only C++17 event bus library that doesn't require you to inherit from any sort of `event` class.

- [Design Goals](#design-goals)
- [Overview](#overview)
- [Features](#features)
- [Integration](#integration)
- [CMake](#cmake)
- [vcpkg](#vcpkg)
Expand All @@ -48,16 +49,20 @@ eventbus
- [Author](#author)
- [Contributors](#contributors)

## Design Goals
## Overview

`eventbus` implements the "Mediator" pattern. This pattern is useful when you want components to communicate to each other without necessarily "knowing" about each other. This can be useful in *some* situations but should be used with caution (there are alternative design patterns to consider).
`eventbus` implements the "Mediator" pattern. This pattern is useful when you want components to communicate to each other without necessarily "knowing" about each other. Effectively, this is a thread safe event dispatcher with a list of callbacks.

- **Do not require event object inheritance** I wanted to implement an event bus system that doesn't require users to inherit from some base `Event` class in order to use the event class.
- **Flexible Callback Types** It's important that the library supports a variety different types of callbacks including:
## Features

- **Does not require event object inheritance** A base `Event` class is not requied for use with `dp::event_bus`. Any class/struct can be used as an event object.
- **Flexible Callback Types** `eventbus` supports a variety different types of callbacks including:
- Lambdas
- Class member functions
- Free functions
- **Flexible Callbacks** Callbacks should be able to take no input parameters, the event type by `const&` or by value.
- **Flexible Callbacks** No parameter callbacks are also supported as well as taking the event type by value or by `const &`.
- **RAII de-registrations** The handler registration objects automatically de-register the handler upon destruction.
- **Thread safety** Multiple threads can fire events at once to the same `event_bus`. Handlers can also be registered from different threads.

## Integration

Expand Down Expand Up @@ -109,14 +114,14 @@ void event_callback(event_type evt)
}

dp::event_bus evt_bus;
evt_bus.register_handler<event_type>(&event_callback)
const auto registration_handler = evt_bus.register_handler<event_type>(&event_callback)
````
#### Lambda
````cpp
dp::event_bus evt_bus;
evt_bus.register_handler<event_type>([](const event_type& evt)
const auto registration_handler = evt_bus.register_handler<event_type>([](const event_type& evt)
{
// logic code...
});
Expand All @@ -137,7 +142,7 @@ class event_handler
// other code
dp::event_bus evt_bus;
event_handler handler;
evt_bus.register_handler<event_type>(&handler, &event_handler::on_event);
const auto registration_handler = evt_bus.register_handler<event_type>(&handler, &event_handler::on_event);
````

**Note:** You can't mix a class instance of type `T` with the member function of another class (i.e. `&U::function_name`).
Expand All @@ -159,6 +164,11 @@ A complete example can be seen in the [demo](https://github.com/DeveloperPaul123

In general, all callback functions **must** return `void`. Currently, `eventbus` only supports single argument functions as callbacks.

The following use cases are not supported:

- Registering a callback inside an event callback.
- De-registering a callback inside an event callback.

## Contributing

If you find an issue with this library please file an [issue](https://github.com/DeveloperPaul123/eventbus/issues). Pull requests are also welcome! Please see the [contribution guidelines](CONTRIBUTING.md) for more information.
Expand Down

0 comments on commit 2ad8a77

Please sign in to comment.