Add cancel/2 function, which takes an options argument
When futures are canceled, they may have a `ready` message already in the
mailbox. There is now a way to flush that message with the `[flush]` option.
That is currently the only option.
diff --git a/src/erlfdb.erl b/src/erlfdb.erl
index d248c88..aca9f55 100644
--- a/src/erlfdb.erl
+++ b/src/erlfdb.erl
@@ -32,6 +32,7 @@
commit/1,
reset/1,
cancel/1,
+ cancel/2,
% Future Specific functions
is_ready/1,
@@ -189,6 +190,14 @@
ok = erlfdb_nif:transaction_cancel(Tx).
+cancel(?IS_FUTURE = Future, Options) ->
+ ok = erlfdb_nif:future_cancel(Future),
+ case erlfdb_util:get(Options, flush, false) of
+ true -> flush_future_message(Future);
+ false -> ok
+ end.
+
+
is_ready(?IS_FUTURE = Future) ->
erlfdb_nif:future_is_ready(Future).
@@ -208,6 +217,15 @@
end.
+flush_future_message(?IS_FUTURE = Future) ->
+ {erlfdb_future, MsgRef, _Res} = Future,
+ receive
+ {MsgRef, ready} -> ok
+ after
+ 0 -> ok
+ end.
+
+
wait(?IS_FUTURE = Future) ->
wait(Future, []);