@@ -15,12 +15,12 @@ The fastest way to get started with QB is to use our boilerplate project generat
1515
1616** Using cURL:** 
1717``` bash 
18- curl -o- https://raw.githubusercontent.com/isndev/qb/master /script/qb-new-project.sh |  bash /dev/stdin MyProject
18+ curl -o- https://raw.githubusercontent.com/isndev/qb/main /script/qb-new-project.sh |  bash /dev/stdin MyProject
1919``` 
2020
2121** Using Wget:** 
2222``` bash 
23- wget -qO- https://raw.githubusercontent.com/isndev/qb/master /script/qb-new-project.sh |  bash /dev/stdin MyProject
23+ wget -qO- https://raw.githubusercontent.com/isndev/qb/main /script/qb-new-project.sh |  bash /dev/stdin MyProject
2424``` 
2525
2626** Build and run:** 
@@ -39,32 +39,31 @@ cd build && make
3939
4040//  Define an event
4141struct  GreetingEvent  : qb::Event {
42-     std ::string message;
42+     qb ::string message;
4343    GreetingEvent(std::string msg) : message(std::move(msg)) {}
4444};
4545
4646// Define an actor
4747class GreeterActor : public qb::Actor {
4848public:
49-     bool onInit() override {
50-         registerEvent<GreetingEvent >(* this);
49+     bool onInit() final {
50+         registerEvent<GreetingEvent >(* this); // register event
51+         push<GreetingEvent >(id(), "Hello !"); // send to self 
5152        return true;
5253    }
5354
5455    void on(const GreetingEvent& event) { 
5556        qb::io::cout() << "Received: " << event.message << std::endl; 
56-         kill(); // Job done 
57+         kill(); // Job done, kill me  
5758    } 
5859};
5960
6061int  main () {
6162    qb::Main engine; 
62-     auto actor_id = engine.addActor<GreeterActor>(0); 
63-     
64-     // Send a message to our actor 
65-     engine.push<GreetingEvent>(actor_id, "Hello QB!"); 
63+     auto actor_id = engine.addActor<GreeterActor>(0); // add actor to core 0 
6664
6765    engine.start(); 
66+     engine.join(); 
6867    return 0; 
6968}
7069``` 
@@ -111,8 +110,9 @@ QB is built for speed from the ground up:
111110
112111``` cpp 
113112//  Distribute work across all CPU cores automatically
114- qb::Main engine (std: : thread : :hardware_concurrency()) ;
113+ qb::Main engine;
115114
115+ auto  num_cores = std::thread::hardware_concurrency();
116116//  Add worker actors to different cores
117117for  (int  i = 0 ; i < num_cores; ++i) {
118118    engine.addActor<WorkerActor>(i); 
@@ -129,14 +129,18 @@ for (int i = 0; i < num_cores; ++i) {
129129``` cpp 
130130//  HTTP Server in 10 lines
131131class  HttpActor  : public  qb ::Actor, public qb::http::Server<> {
132-     bool onInit() override  { 
132+     bool onInit() final  {
133133        router().get("/api/status", [ ] (auto ctx) {
134134            ctx->response().body() = R"({"status": "ok"})";
135135            ctx->complete();
136136        });
137137
138138        router().compile();
139-         return listen({"tcp://0.0.0.0:8080"}); 
139+         if (!listen({"tcp://0.0.0.0:8080"}))
140+             return false;
141+ 
142+         start(); // start async io 
143+         return true; 
140144    } 
141145};
142146``` 
0 commit comments