-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathasync.cpp
More file actions
44 lines (39 loc) · 986 Bytes
/
Copy pathasync.cpp
File metadata and controls
44 lines (39 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <mage.h>
#include <future>
#include <iostream>
using namespace mage;
using namespace std;
//
// All the code (well, almost)
// is the same as simple.cpp
//
int main() {
mage::RPC client("game", "localhost:8080");
//
// However, we will store the result into
// a future object
//
Json::Value params;
std::future<Json::Value> res;
//
// I put things in my Json::Value.
//
params["password"] = "test";
//
// We make the call
//
// The third argument is meant to define the nature of
// the future call:
//
// - false: Run at call time (when you call res.get())
// - true: Run asynchronously
//
try {
res = client.Call("user.register", params, true);
cout << "user.register: " << res.get() << endl;
} catch (mage::MageRPCError e) {
cerr << "An RPC error has occured: " << e.what() << " (code " << e.code() << ")" << endl;
} catch (mage::MageErrorMessage e) {
cerr << "mymodule.mycommand responded with an error: " << e.code() << endl;
}
}