Skip to content

Commit

Permalink
close #66 .
Browse files Browse the repository at this point in the history
make sure that last_seq is always defined. Thanks for the report.
  • Loading branch information
benoitc committed Feb 12, 2012
1 parent 051dff8 commit 7148bbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
13 changes: 7 additions & 6 deletions include/couchbeam.hrl
Expand Up @@ -35,10 +35,10 @@

-type ejson_key() :: binary() | atom().

-type ejson_term() :: ejson_array()
| ejson_object()
| ejson_string()
| ejson_number()
-type ejson_term() :: ejson_array()
| ejson_object()
| ejson_string()
| ejson_number()
| true | false | null.

-type ejson_string() :: binary().
Expand Down Expand Up @@ -124,6 +124,7 @@

-record(changes_args, {
type = normal,
since = 0,
http_options = []}).
-type changes_args() :: #changes_args{}.

Expand All @@ -135,8 +136,8 @@
modstate,
db,
options}).

-define(USER_AGENT, "couchbeam/0.7.0").

-define(DEPRECATED(Old, New, When),
-define(DEPRECATED(Old, New, When),
couchbeam_util:deprecated(Old, New, When)).
9 changes: 7 additions & 2 deletions src/couchbeam_changes.erl
Expand Up @@ -177,7 +177,8 @@ parse_changes_options([include_docs|Rest], #changes_args{http_options=Opts} = Ar
parse_changes_options(Rest, Args#changes_args{http_options=Opts1});
parse_changes_options([{since, Since}|Rest], #changes_args{http_options=Opts} = Args) ->
Opts1 = [{"since", Since}|Opts],
parse_changes_options(Rest, Args#changes_args{http_options=Opts1});
parse_changes_options(Rest,
Args#changes_args{since=Since, http_options=Opts1});
parse_changes_options([{timeout, Timeout}|Rest], #changes_args{http_options=Opts} = Args) ->
Opts1 = [{"timeout", Timeout}|Opts],
parse_changes_options(Rest, Args#changes_args{http_options=Opts1});
Expand Down Expand Up @@ -214,7 +215,10 @@ parse_changes_options([_|Rest], Args) ->

-spec changes_loop(Args::changes_args(), UserFun::function(),
Params::{Url::string(), IbrowseOpts::list()}) -> ok.
changes_loop(Args, UserFun, Params) ->
changes_loop(#changes_args{since=Since}=Args, UserFun, Params) ->
%% initialize last_seq /
put(last_seq, Since),

Callback = case Args#changes_args.type of
continuous ->
fun(200, _Headers, DataStreamFun) ->
Expand All @@ -241,6 +245,7 @@ do_stream(Db, UserFun, Options) ->

do_stream(#db{server=Server, options=IbrowseOpts}=Db, UserFun, Options,
StartRef) ->

Args = parse_changes_options(Options),
Url = couchbeam:make_url(Server, [couchbeam:db_url(Db), "/_changes"],
Args#changes_args.http_options),
Expand Down
4 changes: 3 additions & 1 deletion src/gen_changes.erl
Expand Up @@ -68,12 +68,14 @@ init([Module, Db, Options, InitArgs]) ->
{ok, StartRef, ChangesPid} ->
erlang:monitor(process, ChangesPid),
unlink(ChangesPid),
LastSeq = proplists:get_value(since, Options, 0),
{ok, #gen_changes_state{start_ref=StartRef,
changes_pid=ChangesPid,
mod=Module,
modstate=ModState,
db=Db,
options=Options}};
options=Options,
last_seq=LastSeq}};
{error, Error} ->
Module:terminate(Error, ModState),
{stop, Error}
Expand Down

0 comments on commit 7148bbd

Please sign in to comment.