santazhang / simple-rpc

Simple RPC in C++, with Python binding
http://www.yzhang.net/simple-rpc/
BSD 3-Clause "New" or "Revised" License
27 stars 6 forks source link

a delayed return interface #9

Closed shuaimu closed 10 years ago

santazhang commented 10 years ago

Simple-rpc supports 3 kinds of RPC: normal, fast, raw.

raw RPC is useful when the RPC request cannot be replied in a timely fashion. It gives programmer the option to reply RPC at any time, or even drop the connection.

But dealing with raw RPC is painful, especially the serialization part.

So it's a good idea to provide something less bare metal. A defer RPC handles serialization, and will have more human friendly signature:

Instead of rpc(Request* req, ServerConnection* sconn), we have rpc(input&, output*, defer). So programmers can write this:

rpc(input&, output* out, defer) {
    defer->run_async([output* ] {
         *out = some_func();
         defer->reply(); // also deletes the defer object
    });
}