diff options
| author | Zheng Chao <[email protected]> | 2022-11-22 17:52:35 +0800 |
|---|---|---|
| committer | Zheng Chao <[email protected]> | 2022-11-22 17:52:35 +0800 |
| commit | 704c1d22adf1e3b446fc144dd67e42aa598baa72 (patch) | |
| tree | a0669db7456c208d98bae38413b729067ae807e2 /examples | |
| parent | 8576db78045570f27e7bf862fbd3056d22994548 (diff) | |
:recycle: Rename Async API. Add async example.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/async_example.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/examples/async_example.c b/examples/async_example.c index 825d7a3..b9bc5a1 100644 --- a/examples/async_example.c +++ b/examples/async_example.c @@ -1,6 +1,20 @@ #include "swarmkv/swarmkv.h" -#include "stdlib.h" -#include "stdio.h" +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +struct my_context +{ + int got_reply; + long long reply_integer; +}; +void my_on_reply_callback(const struct swarmkv_reply *reply, void * arg) +{ + struct my_context *ctx=(struct my_context *)arg; + ctx->got_reply=1; + ctx->reply_integer=reply->integer; + return; +} int main(int argc, char **argv) { struct swarmkv_options *opts[2]; @@ -19,6 +33,17 @@ int main(int argc, char **argv) return -1; } } + struct my_context *ctx=NULL; + ctx=(struct my_context*)calloc(sizeof(struct my_context), 1); + swarmkv_async_command(db[0], my_on_reply_callback, ctx, "HSET uid001 name zhangsan age 18"); + + while(!ctx->got_reply) + { + //do something else + sleep(1); + } + printf("HSET %lld items\n", ctx->reply_integer); + free(ctx); for(size_t i=0; i<2; i++) { swarmkv_close(db[i]); |
