mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-05-07 12:22:57 +00:00
StackTrace for Dart 2.17
This commit is contained in:
parent
9d289ac202
commit
89e1897dfd
@ -31,6 +31,8 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
|
|
||||||
late T _result;
|
late T _result;
|
||||||
|
|
||||||
|
late StackTrace _stackTrace;
|
||||||
|
|
||||||
List<Function> _errorCallbacks = <Function>[];
|
List<Function> _errorCallbacks = <Function>[];
|
||||||
|
|
||||||
List<Function(ProgressType, int, int)> _progressCallbacks =
|
List<Function(ProgressType, int, int)> _progressCallbacks =
|
||||||
@ -63,17 +65,25 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncReply<R> then<R>(FutureOr<R> onValue(T value), {Function? onError}) {
|
AsyncReply<R> then<R>(FutureOr<R> onValue(T value), {Function? onError}) {
|
||||||
if (onError != null) {}
|
_stackTrace = StackTrace.current;
|
||||||
|
|
||||||
_callbacks.add(onValue);
|
_callbacks.add(onValue);
|
||||||
|
|
||||||
if (onError != null) {
|
if (onError != null) {
|
||||||
_errorCallbacks.add(onError);
|
_errorCallbacks.add(onError);
|
||||||
//print("On ERROR $onError ${this.hashCode}");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_resultReady) onValue(result as T);
|
if (_resultReady) {
|
||||||
|
if (_exception != null) {
|
||||||
|
if (onError != null) {
|
||||||
|
onError(_exception, _stackTrace);
|
||||||
|
} else {
|
||||||
|
throw _exception as AsyncException;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onValue(result as T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//if (R == Null)
|
//if (R == Null)
|
||||||
return AsyncReply<R>();
|
return AsyncReply<R>();
|
||||||
@ -102,13 +112,13 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
|
|
||||||
if (_exception != null) {
|
if (_exception != null) {
|
||||||
if (onError is Function(dynamic, dynamic)) {
|
if (onError is Function(dynamic, dynamic)) {
|
||||||
onError(_exception, null);
|
onError(_exception, _stackTrace);
|
||||||
} else if (onError is Function(dynamic)) {
|
} else if (onError is Function(dynamic)) {
|
||||||
onError(_exception);
|
onError(_exception);
|
||||||
} else if (onError is Function()) {
|
} else if (onError is Function()) {
|
||||||
onError();
|
onError();
|
||||||
} else if (onError is Function(Object, StackTrace)) {
|
} else if (onError is Function(Object, StackTrace)) {
|
||||||
onError(_exception as Object, StackTrace.current);
|
onError(_exception as Object, _stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,13 +172,13 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
else
|
else
|
||||||
_errorCallbacks.forEach((x) {
|
_errorCallbacks.forEach((x) {
|
||||||
if (x is Function(dynamic, dynamic)) {
|
if (x is Function(dynamic, dynamic)) {
|
||||||
x(_exception, null);
|
x(_exception, _stackTrace);
|
||||||
} else if (x is Function(dynamic)) {
|
} else if (x is Function(dynamic)) {
|
||||||
x(_exception);
|
x(_exception);
|
||||||
} else if (x is Function()) {
|
} else if (x is Function()) {
|
||||||
x();
|
x();
|
||||||
} else if (x is Function(Object, StackTrace)) {
|
} else if (x is Function(Object, StackTrace)) {
|
||||||
x(_exception as Object, StackTrace.current);
|
x(_exception as Object, _stackTrace);
|
||||||
} else if (x is Function(AsyncException)) {
|
} else if (x is Function(AsyncException)) {
|
||||||
x(_exception!);
|
x(_exception!);
|
||||||
} else {
|
} else {
|
||||||
@ -198,9 +208,12 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AsyncReply.ready(T result) {
|
AsyncReply.ready(T result) {
|
||||||
|
_stackTrace = StackTrace.current;
|
||||||
_resultReady = true;
|
_resultReady = true;
|
||||||
_result = result;
|
_result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncReply() {}
|
AsyncReply() {
|
||||||
|
_stackTrace = StackTrace.current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user