Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename "keep until" conditions to "keep while" conditions #18

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/overview.edoc
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ tree nodes `stock' and `wood' were created if they were missing. After
`<<"walnut">>' is removed, they will stay in the tree with possibly neither
payload nor child nodes.

Khepri has the concept of <em>`keep_until' conditions</em>. A `keep_until'
Khepri has the concept of <em>`keep_while' conditions</em>. A `keep_while'
condition is like the conditions which can be used inside path pattern. When a
node is inserted or updated, it is possible to set `keep_until' conditions:
node is inserted or updated, it is possible to set `keep_while' conditions:
when these conditions evaluate to false, the tree node is removed from the
tree.

Expand All @@ -182,10 +182,10 @@ to make sure it is removed after its last child node is removed:
```
%% We keep [stock, wood] as long as its child nodes count is strictly greater
%% then zero.
KeepUntilCondition = #{[stock, wood] => #if_child_list_length{count = {gt, 0}}}.
KeepWhileCondition = #{[stock, wood] => #if_child_list_length{count = {gt, 0}}}.
'''

`keep_until' conditions on self (like the example above) are not evaluated on
`keep_while' conditions on self (like the example above) are not evaluated on
the first insert though.

== Khepri API ==
Expand Down
4 changes: 2 additions & 2 deletions src/internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

-record(put, {path :: khepri_path:pattern(),
payload = none :: khepri_machine:payload(),
extra = #{} :: #{keep_until =>
khepri_machine:keep_untils_map()}}).
extra = #{} :: #{keep_while =>
khepri_machine:keep_while_conds_map()}}).

-record(delete, {path :: khepri_path:pattern()}).

Expand Down
8 changes: 4 additions & 4 deletions src/khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1009,14 +1009,14 @@ info(StoreId) ->
Nodes = lists:sort([Node || {_, Node} <- members(StoreId)]),
lists:foreach(fun(Node) -> io:format("~ts~n", [Node]) end, Nodes),

case khepri_machine:get_keep_untils_state(StoreId) of
{ok, KeepUntils} when KeepUntils =/= #{} ->
case khepri_machine:get_keep_while_conds_state(StoreId) of
{ok, KeepWhileConds} when KeepWhileConds =/= #{} ->
io:format("~n\033[1;32m== LIFETIME DEPS ==\033[0m~n", []),
WatcherList = lists:sort(maps:keys(KeepUntils)),
WatcherList = lists:sort(maps:keys(KeepWhileConds)),
lists:foreach(
fun(Watcher) ->
io:format("~n\033[1m~p depends on:\033[0m~n", [Watcher]),
WatchedsMap = maps:get(Watcher, KeepUntils),
WatchedsMap = maps:get(Watcher, KeepWhileConds),
Watcheds = lists:sort(maps:keys(WatchedsMap)),
lists:foreach(
fun(Watched) ->
Expand Down
6 changes: 3 additions & 3 deletions src/khepri_condition.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

%% @doc Condition support.
%%
%% Conditions can be used in path patterns and `keep_until' conditions.
%% Conditions can be used in path patterns and `keep_while' conditions.
%%
%% A condition is an Erlang record defining a specific property. Some of them
%% have arguments to further define the condition.
Expand Down Expand Up @@ -222,7 +222,7 @@
if_child_list_version() |
if_child_list_length().

-type keep_until() :: #{khepri_path:path() => condition()}.
-type keep_while() :: #{khepri_path:path() => condition()}.

-export([compile/1,
applies_to_grandchildren/1,
Expand All @@ -236,7 +236,7 @@

-export_type([condition/0,
comparison_op/1,
keep_until/0]).
keep_while/0]).

-spec compile(Condition) -> Condition when
Condition :: khepri_path:pattern_component().
Expand Down
Loading