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 Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/d9837e1d Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/d9837e1d Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/d9837e1d Branch: refs/heads/1901-atomic-multipart-retries Commit: d9837e1dadb7b49a032084021b8aa01f299dda4e Parents: 0b45050 Author: Adam Kocoloski <[email protected]> Authored: Thu Sep 12 12:56:50 2013 -0400 Committer: Adam Kocoloski <[email protected]> Committed: Wed Oct 2 12:11:24 2013 -0400 ---------------------------------------------------------------------- .../src/couch_replicator_api_wrap.erl | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/d9837e1d/src/couch_replicator/src/couch_replicator_api_wrap.erl ---------------------------------------------------------------------- diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl b/src/couch_replicator/src/couch_replicator_api_wrap.erl index fccb759..2b8a636 100644 --- a/src/couch_replicator/src/couch_replicator_api_wrap.erl +++ b/src/couch_replicator/src/couch_replicator_api_wrap.erl @@ -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}) ->
