Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Use spawn_monitor to await process completion
Browse files Browse the repository at this point in the history
BugzID: 13133
  • Loading branch information
Robert Newson committed Jan 16, 2012
1 parent 121c71c commit effae95
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions apps/couch/src/couch_doc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,10 @@ atts_to_mp([Att | RestAtts], Boundary, WriteFun,


doc_from_multi_part_stream(ContentType, DataFun) ->
Parent = self(),
Parser = spawn_link(fun() ->
{Parser, ParserRef} = spawn_monitor(fun() ->
{<<"--">>, _, _} = couch_httpd:parse_multipart_request(
ContentType, DataFun,
fun(Next) -> mp_parse_doc(Next, []) end),
unlink(Parent),
Parent ! {self(), finished}
fun(Next) -> mp_parse_doc(Next, []) end)
end),
Parser ! {get_doc_bytes, self()},
receive
Expand All @@ -505,7 +502,7 @@ doc_from_multi_part_stream(ContentType, DataFun) ->
A
end, Doc#doc.atts),
WaitFun = fun() ->
receive {Parser, finished} -> ok end,
receive {'DOWN', ParserRef, _, _, _} -> ok end,
erlang:put(mochiweb_request_recv, true)
end,
{ok, Doc#doc{atts=Atts2}, WaitFun, Parser}
Expand Down

0 comments on commit effae95

Please sign in to comment.