30 lines
905 B
C++
30 lines
905 B
C++
#pragma once
|
||
#include <functional>
|
||
#include <QList>
|
||
#include <QPointer>
|
||
#include <QObject>
|
||
#include "IApiCall.hpp"
|
||
|
||
namespace geopro::net {
|
||
|
||
// 并发汇聚 N 个 IApiCall:全成功 → succeeded(按下标对齐);任一失败 → fail-fast:
|
||
// failed(index,resp) + abort 其余在飞 call。安全不变量见 spec §5.0。
|
||
class ApiBatch : public QObject {
|
||
Q_OBJECT
|
||
public:
|
||
using Predicate = std::function<bool(const ApiResponse&)>;
|
||
ApiBatch(QList<IApiCall*> calls, Predicate isFailure, QObject* parent = nullptr); // 接管 calls
|
||
void abort();
|
||
signals:
|
||
void succeeded(const QList<geopro::net::ApiResponse>& responses);
|
||
void failed(int index, const geopro::net::ApiResponse& resp);
|
||
private:
|
||
QList<QPointer<IApiCall>> calls_;
|
||
QList<ApiResponse> responses_;
|
||
Predicate isFailure_;
|
||
int remaining_ = 0;
|
||
bool aborted_ = false;
|
||
};
|
||
|
||
} // namespace geopro::net
|