From e9eb29719b6ef99810ef6615c09beb3993880cac Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 8 Jan 2016 13:03:47 -0800 Subject: [core] Simplify logic for notification with pre-existing response We already had a condition that checks if a response is immediately available for an incoming request. Call the callback there, rather than in addObserver. --- platform/default/online_file_source.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 6a65bb44e5..755c5e590d 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -200,11 +200,10 @@ void OnlineFileSource::Impl::add(Resource resource, FileRequest* req, Callback c if (request.getResponse()) { // We've at least obtained a cache value, potentially we also got a final response. - // The observers have been notified already; send what we have to the new one as well. - // Before returning the existing response, make sure that it is still fresh, or update the // `stale` flag. request.checkResponseFreshness(); + callback(*request.getResponse()); if (request.getResponse()->stale && !request.realRequest) { // We've returned a stale response; now make sure the requester also gets a fresh @@ -334,11 +333,6 @@ OnlineFileRequestImpl::~OnlineFileRequestImpl() { void OnlineFileRequestImpl::addObserver(FileRequest* req, Callback callback) { observers.emplace(req, callback); - - if (response) { - // We've got a response, so send the (potentially stale) response to the requester. - callback(*response); - } } void OnlineFileRequestImpl::removeObserver(FileRequest* req) { -- cgit v1.2.1