File indexing completed on 2024-05-05 16:47:04

0001 // SPDX-FileCopyrightText: 2021 Carson Black <uhhadd@gmail.com>
0002 //
0003 // SPDX-License-Identifier: MIT
0004 
0005 #pragma once
0006 
0007 #include <QNetworkReply>
0008 
0009 #include "coroutine_integration.h"
0010 
0011 template<>
0012 struct Croutons::transformer<QNetworkReply*> {
0013     static auto transform(QNetworkReply* it) {
0014         auto future = Future<QNetworkReply*>();
0015 
0016         QObject::connect(it, &QNetworkReply::finished, it, [future, it]() {
0017             if (it->error() == QNetworkReply::NoError) {
0018                 future.succeed(it);
0019             } else {
0020                 future.fail(it);
0021             }
0022         });
0023 
0024         return future;
0025     }
0026 };