From 8fb810c54860132506ede4feb541bf0ce653dd29 Mon Sep 17 00:00:00 2001 From: flamingcow Date: Thu, 9 May 2019 23:37:00 -0700 Subject: [PATCH] Use InTransaction() for events --- firecgi | 2 +- stream.cc | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/firecgi b/firecgi index 8bd0813..b5b0cbd 160000 --- a/firecgi +++ b/firecgi @@ -1 +1 @@ -Subproject commit 8bd0813161fcb60871f415bd5b2512f2ec54b553 +Subproject commit b5b0cbd599aefa4f8243de1368858023c0a5de5c diff --git a/stream.cc b/stream.cc index ef89cd4..ededd93 100644 --- a/stream.cc +++ b/stream.cc @@ -6,15 +6,16 @@ Stream::Stream(firecgi::Request* request) : request_(request) {} bool Stream::WriteEvent(const std::string& data, uint64_t id, const std::string& type) { - if (id) { - request_->WriteBody("id: ", std::to_string(id), "\n"); - } - if (!type.empty()) { - request_->WriteBody("event: ", type, "\n"); - } - request_->WriteBody("data: ", data, "\n"); - - return request_->Flush(); + return request_->InTransaction([=]() { + if (id) { + request_->WriteBody("id: ", std::to_string(id), "\n"); + } + if (!type.empty()) { + request_->WriteBody("event: ", type, "\n"); + } + request_->WriteBody("data: ", data, "\n\n"); + return request_->Flush(); + }); } bool Stream::End() {