From 2caf6c22be866a06b1b751a9462b619fda06ef64 Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Fri, 1 Dec 2023 16:55:24 +0800 Subject: [PATCH] docs: add async write --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 96f8c9f..8c04f0c 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,22 @@ Write data by rows: greptimedb:write(Client, Metric, Points). ``` +Write in async: + +```erlang +Ref = make_ref(), +Pid = self(), +ResultCallback = {fun(Reply) -> Pid ! {{Ref, reply}, Reply} end, []}, + +ok = greptimedb:async_write(Client, Metric, Points, ResultCallback), +receive + {{Ref, reply}, Reply} -> + io:format("Reply ~w~n", [Reply]) +end. +``` + Batch write: + ```erlang Metric1 = <<"temperatures">>, Points1 = [...], @@ -64,6 +79,21 @@ Batch = [{Metric1, Points1}, {Metric2, Points}], {ok, _} = greptimedb:write_batch(Client, Batch). ``` +Batch write in async: + +```erlang +Batch = ..., +Ref = make_ref(), +Pid = self(), +ResultCallback = {fun(Reply) -> Pid ! {{Ref, reply}, Reply} end, []}, + +ok = greptimedb:async_write_batch(Client, Batch, ResultCallback), +receive + {{Ref, reply}, Reply} -> + io:format("Reply ~w~n", [Reply]) +end. +``` + Streaming write: ```erlang