2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-09-30 19:13:19 +00:00

AutoReconnect

This commit is contained in:
2022-08-11 21:28:41 +03:00
parent c9ead2dabd
commit 083ea92d3b
10 changed files with 407 additions and 271 deletions

View File

@@ -12,7 +12,7 @@ class AsyncQueue<T> extends AsyncReply<T?> {
_list.add(reply);
//super._resultReady = false;
super.setResultReady(false);
super.ready = false; // setResultReady(false);
reply.then(processQueue);
}
@@ -35,7 +35,7 @@ class AsyncQueue<T> extends AsyncReply<T?> {
break;
//super._resultReady = (_list.length == 0);
super.setResultReady(_list.length == 0);
super.ready = _list.length == 0; // .setResultReady(_list.length == 0);
}
AsyncQueue() {}

View File

@@ -23,6 +23,8 @@ SOFTWARE.
*/
import 'dart:async';
import 'dart:core';
import 'package:esiur/esiur.dart';
import 'AsyncException.dart';
import 'ProgressType.dart';
@@ -55,9 +57,9 @@ class AsyncReply<T> implements Future<T> {
return _result;
}
void setResultReady(bool val) {
_resultReady = val;
}
// void setResultReady(bool val) {
// _resultReady = val;
// }
AsyncReply<T> next(Function(T) callback) {
then(callback);
@@ -127,7 +129,11 @@ class AsyncReply<T> implements Future<T> {
AsyncReply<T> timeout(Duration timeLimit, {FutureOr<T?> onTimeout()?}) {
Future.delayed(timeLimit, () {
if (!_resultReady && _exception == null) onTimeout?.call();
if (!_resultReady && _exception == null) {
triggerError(AsyncException(ErrorType.Management,
ExceptionCode.Timeout.index, "Execution timeout expired"));
onTimeout?.call();
}
});
return this;
@@ -152,6 +158,7 @@ class AsyncReply<T> implements Future<T> {
AsyncReply<T> trigger(T result) {
if (_resultReady) return this;
if (_exception != null) return this;
_result = result;
_resultReady = true;

View File

@@ -34,5 +34,6 @@ enum ExceptionCode {
AlreadyListened,
AlreadyUnlistened,
NotListenable,
ParseError
ParseError,
Timeout
}