forked from deriv-com/flutter-deriv-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_manager.dart
37 lines (30 loc) · 1.18 KB
/
call_manager.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import 'dart:async';
import 'package:flutter_deriv_api/basic_api/helper/response_mapper.dart';
import 'package:flutter_deriv_api/basic_api/request.dart';
import 'package:flutter_deriv_api/basic_api/response.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
/// Api call manager abstract class
class CallManager extends BaseCallManager<Future<Response>> {
/// Initializes
CallManager(BaseAPI api) : super(api);
@override
void handleResponse({
required int requestId,
required Map<String, dynamic> response,
}) {
super.handleResponse(requestId: requestId, response: response);
final Completer<Response>? responseCompleter =
pendingRequests[requestId]?.responseCompleter;
if (responseCompleter?.isCompleted == false) {
responseCompleter!.complete(getResponseByMsgType(response));
}
pendingRequests.remove(requestId);
}
@override
Future<Response> call({
required Request request,
List<String> nullableKeys = const <String>[],
}) async =>
addToChannel(request: request, nullableKeys: nullableKeys);
}