Permalink
Browse files

close #66 .

make sure that last_seq is always defined. Thanks for the report.
  • Loading branch information...
1 parent 051dff8 commit 7148bbdb19aca91b7b74e5392a23c94d33ca4e27 @benoitc committed Feb 12, 2012
Showing with 17 additions and 9 deletions.
  1. +7 −6 include/couchbeam.hrl
  2. +7 −2 src/couchbeam_changes.erl
  3. +3 −1 src/gen_changes.erl
View
@@ -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().
@@ -124,6 +124,7 @@
-record(changes_args, {
type = normal,
+ since = 0,
http_options = []}).
-type changes_args() :: #changes_args{}.
@@ -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)).
@@ -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});
@@ -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) ->
@@ -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),
View
@@ -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}

0 comments on commit 7148bbd

Please sign in to comment.