summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2013-09-12 12:56:50 -0400
committerAdam Kocoloski <adam@cloudant.com>2013-10-02 15:35:54 -0400
commit37aa350109753c5f3648fcfa04db812542477543 (patch)
tree1bf9684bc19482ca8f5e33990e2fe02f791fb3bf
parent0b450507670a4649255c2ac4c41d6aa7ae81e45a (diff)
downloadcouchdb-37aa350109753c5f3648fcfa04db812542477543.tar.gz
Simplify doc_streamer initialization
The unlink at the end is a noop, so we can simplify this to use spawn_link/3 and the fully-exported function call instead of spawn_link/1 and a closure. BugzID: 20822
-rw-r--r--src/couch_replicator/src/couch_replicator_api_wrap.erl24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl b/src/couch_replicator/src/couch_replicator_api_wrap.erl
index fccb7595e..f779747bf 100644
--- a/src/couch_replicator/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator/src/couch_replicator_api_wrap.erl
@@ -221,7 +221,7 @@ open_doc_revs(#httpdb{} = HttpDb, Id, Revs, Options, Fun, Acc) ->
),
#httpdb{retries = Retries, wait = Wait0} = HttpDb,
Wait = 2 * erlang:min(Wait0 * 2, ?MAX_WAIT),
- twig:log(notice,"Retrying GET to ~s in ~p seconds due to error ~p",
+ ?LOG_INFO("Retrying GET to ~s in ~p seconds due to error ~p",
[Url, Wait / 1000, Else]
),
ok = timer:sleep(Wait),
@@ -834,6 +834,12 @@ rev_to_str({_Pos, _Id} = Rev) ->
rev_to_str(Rev) ->
Rev.
+write_fun() ->
+ fun(Data) ->
+ receive {get_data, Ref, From} ->
+ From ! {data, Ref, Data}
+ end
+ end.
stream_doc({JsonBytes, Atts, Boundary, Len}) ->
case erlang:erase({doc_streamer, Boundary}) of
@@ -843,17 +849,11 @@ stream_doc({JsonBytes, Atts, Boundary, Len}) ->
_ ->
ok
end,
- Self = self(),
- DocStreamer = spawn_link(fun() ->
- couch_doc:doc_to_multi_part_stream(
- Boundary, JsonBytes, Atts,
- fun(Data) ->
- receive {get_data, Ref, From} ->
- From ! {data, Ref, Data}
- end
- end, true),
- unlink(Self)
- end),
+ DocStreamer = spawn_link(
+ couch_doc,
+ doc_to_multi_part_stream,
+ [Boundary, JsonBytes, Atts, write_fun(), true]
+ ),
erlang:put({doc_streamer, Boundary}, DocStreamer),
{ok, <<>>, {Len, Boundary}};
stream_doc({0, Id}) ->