瀏覽代碼

Enable pid storage and others

develop-pid
Pedram Nimreezi 8 年之前
父節點
當前提交
3108f593d2
共有 2 個文件被更改,包括 22 次插入5 次删除
  1. +19
    -2
      src/glc.erl
  2. +3
    -3
      src/glc_code.erl

+ 19
- 2
src/glc.erl 查看文件

@ -322,9 +322,10 @@ reset_counters(Module) ->
reset_counters(Module, Counter) ->
Module:reset_counters(Counter).
prepare_store(Store) when not is_list(Store) -> Store;
prepare_store(Store) ->
lists:map(fun({K, V}) when is_pid(V)
-> {K, {pid, binary_to_list(term_to_binary(V))}} ;
lists:map(fun({K, V}) when is_pid(V); is_port(V); is_reference(V)
-> {K, {other, binary_to_list(term_to_binary(V))}} ;
({K, V}) -> {K, V}
end, Store).
@ -1030,6 +1031,22 @@ events_test_() ->
?assertEqual(1, Mod:info(job_error)),
?assertEqual(b, receive {b=Msg, _Store} -> Msg after 0 -> notcalled end)
end
},
{"with pid storage test",
fun() ->
Self = self(),
XPid = spawn(fun() -> receive {msg, Msg, Pid} -> Self ! {Msg, Pid} end end),
Store = [{stored, XPid}],
{compiled, Mod} = setup_query(testmod27,
glc:with(glc:eq(a, 1), fun(Event, _EStore) ->
{ok, Pid} = glc:get(testmod27, stored),
Pid ! {msg, gre:fetch(a, Event), Self}
end),
Store),
glc:handle(Mod, gre:make([{a,1}], [list])),
?assertEqual(1, Mod:info(output)),
?assertEqual(1, receive {Msg, Pid} -> Pid ! Msg after 2 -> notcalled end)
end
}
]
}.

+ 3
- 3
src/glc_code.erl 查看文件

@ -203,9 +203,9 @@ abstract_query({any, [{with, _Q, _A}|_] = I}) ->
abstract_query({all, [{with, _Q, _A}|_] = I}) ->
Queries = glc_lib:reduce(glc:all([Q || {with, Q, _} <- I])),
[?erl:abstract(Queries)];
abstract_query({ok, {pid, Pid}}) ->
PidBin = abstract_apply(erlang, 'list_to_binary', [?erl:abstract(Pid)]),
[?erl:tuple([?erl:atom(ok), abstract_apply(erlang, 'binary_to_term', [(PidBin)])])];
abstract_query({ok, {other, Other}}) ->
SpcBin = abstract_apply(erlang, 'list_to_binary', [?erl:abstract(Other)]),
[?erl:tuple([?erl:atom(ok), abstract_apply(erlang, 'binary_to_term', [SpcBin])])];
abstract_query(Query) ->
[?erl:abstract(Query)].

Loading…
取消
儲存