Skip to content

Instantly share code, notes, and snippets.

@bdionne
Created March 8, 2013 13:48
Show Gist options
  • Save bdionne/5116553 to your computer and use it in GitHub Desktop.
Save bdionne/5116553 to your computer and use it in GitHub Desktop.
continuous_changes(DataFun, UserFun) ->
json_stream_parse:events(
DataFun,
fun(Ev) -> parse_changes_line(Ev, UserFun) end).
is_doc(#doc_info{}=_Doc) ->
true;
is_doc(_Else) ->
false.
parse_changes_line(object_start, UserFun) ->
fun(Ev2) ->
json_stream_parse:collect_object(Ev2,
fun(Obj) ->
PDoc = json_to_doc_info(Obj),
UserFun(PDoc),
case is_doc(PDoc) of
true ->
fun(Ev) -> parse_changes_line(Ev, UserFun) end;
false ->
changes_ev_done()
end
end)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment