-
Notifications
You must be signed in to change notification settings - Fork 3
nguyenzung/nodego
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
1. Design:
- App: Run on mainthread, handle callback function. We have a loop run forever to process pushed events
- Modules: TimerModule, API, HTTPServerModule... Each module runs on different threads. We can have more than one thread per module
- When developer create a task, the task is added to a corresponding module. When the module finish the task, the module will push an event to app.
// App
type App struct {
events chan IResult // events chanel, used to receive events from modules
}
// Timer Module
type TimerModule struct {
timers map[*TimerTask]struct{}
events chan IResult // events chanel, used to push events to app
}
// Task to be processed by TimerModule
type TimerTask struct {
interval int
callback func(int)
latestTime int64
}
// When have timeout event, TimerModule push this result to App by using 'events chan IResult'
type TimerTaskResult struct {
timerTask *TimerTask
dt int
}
type IResult interface {
process()
}
// TimerTaskResult need to implement process() from IResult interface
func (timerResult *TimerTaskResult) process() {
timerResult.timerTask.callback(timerResult.dt)
}
2. How to use:
// In main function
func main() {
app := ev.NewApp() // Init app with this command
// TODO
// ....
// ....
//
app.Exec() // Run app with this command
}About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published