wd_event
Introduction
下面让老夫用八级英语介绍一番
The event function is inspired by c#, and based on the event system, we can achieve program decoupling more easily. So rust has also implemented a similar, but richer, lightweight event development package. Project development address:https://gitee.com/yutiandou/wd-event
Overview
The event functions implemented with rust are as follows:
- event add and execute
- Context
- delay event,delay cycle event
- task pool
- object pool
Example
extern wd-event crate
use ;
create a event manager
async
add a event
If a structure implements the Event trait,it can be registered.
- EType::Default: Execute the Event's handle method.
- EType::Mutable: Execute the Event's handle_mut method.
- EType::Async: Execute a async event.
sync
;
let event_one = String from;
es.add.unwrap;
async exec_sequence function execute async event is nonsegmented
;
es.add_async.unwrap;
execute event , non-blocking
- exec_sequence: Execute in order, register first execute first.
- exec_pool: Execute events through the task pool.
- exec_immediately: Execute the event asynchronously immediately.
es.exec_sequence;
es.exec_pool;
es.exec_immediately.await;;
Context
Context is used to pass state and share messages in multiple callbacks to an event. Changing the status of Context will stop the subsequent function calls, only the exec_sequence method and cycle event. Refer to the API documentation for more methods.
//Create context and add a default message
let a:i32 = 1;
es.exec_sequence;
//Gets the default message for the context
//
delay event,delay cycle event
//delay event and cycle event. only the handle_mut method is called
//Once a second
es.delay_exec;
task pool
Task pool functionality, integrated into the event manager. Using the exec_pool function. Of course, the task pool function can also be used separately, as detailed in the API documentation.
object pool
Object pool, currently only a simple implementation. It is worth considering whether rust really needs object pools.