Software /
code /
prosody
Diff
util/httpstream.lua @ 3565:e2cc09e83a3e
util.httpstream: A little refactoring of the coroutine control flow.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 06 Nov 2010 01:08:30 +0500 |
parent | 3564:90f4e6dc1c11 |
child | 3566:75d287daad16 |
line wrap: on
line diff
--- a/util/httpstream.lua Fri Nov 05 03:07:36 2010 +0500 +++ b/util/httpstream.lua Sat Nov 06 01:08:30 2010 +0500 @@ -7,7 +7,8 @@ module("httpstream") -local function parser(data, success_cb, parser_type) +local function parser(success_cb, parser_type) + local data = coroutine.yield(); local function readline() local pos = data:find("\r\n", nil, true); while not pos do @@ -94,14 +95,15 @@ function new(success_cb, error_cb, parser_type) local co = coroutine.create(parser); + coroutine.resume(co, success_cb, parser_type) return { feed = function(self, data) if not data then - if parser_type == "client" then coroutine.resume(co, "", success_cb, parser_type); end + if parser_type == "client" then coroutine.resume(co, ""); end co = deadroutine; return error_cb(); end - local success, result = coroutine.resume(co, data, success_cb, parser_type); + local success, result = coroutine.resume(co, data); if result then co = deadroutine; return error_cb(result);