Skip to content

Commit bf9665c

Browse files
committed
Updated README
1 parent ad06082 commit bf9665c

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class YourEmploy : public WSJCppEmployBase {
7979
YourEmploy();
8080
static std::string name() { return "YourEmploy"; }
8181
virtual bool init() override;
82+
virtual bool deinit() override;
8283
void doSomething();
8384
private:
8485
std::string TAG;
@@ -98,12 +99,23 @@ YourEmploy::YourEmploy()
9899
TAG = YourEmploy::name();
99100
}
100101
102+
bool YourEmploy::init() {
103+
WSJCppLog::info(TAG, "init called");
104+
return true;
105+
}
106+
107+
bool YourEmploy::deinit() {
108+
WSJCppLog::info(TAG, "deinit called");
109+
return true;
110+
}
111+
101112
void YourEmploy::doSomething() {
102113
WSJCppLog::info(TAG, "doSomething called");
103114
}
104115
```
105116

106-
Now you can call you method for employ
117+
1. For call ::init you must call `WSJCppEmployees::init({})` in main function
118+
2. find employ and call you method from any place
107119

108120
```
109121
#inluce <your_employ.h>
@@ -112,7 +124,56 @@ void someFunc() {
112124
YourEmploy *pYourEmploy = findWSJCppEmploy<YourEmploy>();
113125
pYourEmploy->doSomething();
114126
}
127+
128+
void main() {
129+
...
130+
WSJCppEmployees::init({});
131+
someFunc();
132+
}
133+
```
134+
135+
## Initialization employees in order
136+
137+
1. Second employ required init after first
138+
139+
```
140+
141+
// second - will be init after
142+
SecondEmploy::SecondEmploy()
143+
: WSJCppEmployBase(SecondEmploy::name(), {"FirstEmploy"}) {
144+
TAG = SecondEmploy::name();
145+
}
146+
147+
bool SecondEmploy::init() {
148+
// will be called second
149+
}
150+
151+
// first employ - will be init every time
152+
FirstEmploy::FirstEmploy()
153+
: WSJCppEmployBase(FirstEmploy::name(), {}) {
154+
TAG = FirstEmploy::name();
155+
}
156+
157+
bool SecondEmploy::init() {
158+
// will be called first
159+
}
160+
```
161+
Why it can be need? For init some connections or cache data.
162+
For example, you wanna load some data from database
163+
164+
UsersEmploy
165+
- after: DatabaseEmploy
166+
167+
* In DatabaseEmploy::init you can check connection to database and do migration database struct
168+
* In UsersEmploy::init you can use DatabaseEmploy for load user's tokens on server start
169+
170+
2. You wanna init fork some employs
171+
172+
Also you can define on init:
173+
```
174+
WSJCppEmployees::init({"server-start"})
115175
```
176+
So it will be call "::init" employees only there which has this requirements.
116177

117178

118179

0 commit comments

Comments
 (0)