forked from ellie-idb/grpc-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.d
80 lines (59 loc) · 1.41 KB
/
main.d
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module app;
import std.range;
import std.parallelism;
import grpc.core;
import core.thread;
import grpc.server;
import grpc.server.builder;
import helloworld.helloworld;
import google.rpc.status;
import core.atomic;
debug import grpc.logger : gLogger, Verbosity;
__gshared Server server;
extern(C) void handler(int num) nothrow @nogc @system
{
server.shutdown();
}
class HelloWorldServer : Greeter {
private {
shared int count;
}
Status SayHello(HelloRequest req, ref HelloReply reply) {
import std.conv : to;
Status t;
reply.message = "grpc-d-core: Hello, " ~ req.name;
return t;
}
Status SayGoodBye(HelloRequest req, ref HelloReply reply) {
import std.conv : to;
Status t;
reply.message = "grpc-d-core: Hello, " ~ req.name;
return t;
}
this() {
}
~this() {
}
}
void fun() {
foreach (i; 0 .. 5) {
writeln("fun", i);
foreach (num; parallel(iota(5))) {
writeln(num);
}
Thread.sleep(dur!("seconds")(5));
}
}
import std.stdio;
import core.sys.posix.signal;
void main() {
auto t = new Thread({fun();}).start();
signal(SIGINT, &handler);
debug gLogger.minVerbosity = Verbosity.Debug;
ServerBuilder builder = new ServerBuilder();
builder.port = 50051;
server = builder.build();
builder.register!(HelloWorldServer)(server);
server.run();
server.wait();
}