| 1 | | | import 'dart:async'; |
| 2 | | | |
| 3 | | | import 'package:cancelation_token/cancelation_token.dart'; |
| 4 | | | import 'package:meta/meta.dart'; |
| 5 | | | |
| 6 | | | import 'squadron_canceled_exception.dart'; |
| 7 | | | import 'squadron_canceled_exceptions.dart'; |
| 8 | | | import 'squadron_error.dart'; |
| 9 | | | import 'squadron_exception.dart'; |
| 10 | | | import 'squadron_timeout_exception.dart'; |
| 11 | | | import 'task_canceled_exception.dart'; |
| 12 | | | import 'task_terminated_exception.dart'; |
| 13 | | | import 'worker_exception.dart'; |
| 14 | | | |
| 15 | | | const $squadronErrorType = '\$!'; |
| 16 | | | const $workerExceptionType = '\$#'; |
| 17 | | | const $canceledExceptionType = '\$C'; |
| 18 | | | const $canceledExceptionsType = '\$C*'; |
| 19 | | | const $taskCanceledExceptionType = '\$C1'; |
| 20 | | | const $taskTerminatedExceptionType = '\$K'; |
| 21 | | | const $timeoutExceptionType = '\$T'; |
| 22 | | | |
| 23 | | | @internal |
| 24 | | | typedef SquadronExceptionDeserializer = SquadronException? Function(List props); |
| 25 | | | |
| 26 | | | @internal |
| 27 | | 33 | final builtinExceptions = <String, SquadronExceptionDeserializer>{ |
| 28 | | | $canceledExceptionType: SquadronCanceledExceptionExt.deserialize, |
| 29 | | | $timeoutExceptionType: SquadronTimeoutExceptionExt.deserialize, |
| 30 | | | $canceledExceptionsType: SquadronCanceledExceptionsExt.deserialize, |
| 31 | | | $taskCanceledExceptionType: TaskCanceledExceptionExt.deserialize, |
| 32 | | | $taskTerminatedExceptionType: TaskTerminatedExceptionExt.deserialize, |
| 33 | | | $squadronErrorType: SquadronErrorImpl.deserialize, |
| 34 | | | $workerExceptionType: WorkerExceptionImpl.deserialize, |
| 35 | | | }; |
| 36 | | | |
| 37 | | | @internal |
| 38 | | | extension CanceledConversionExt on CanceledException { |
| 39 | | 2 | SquadronException toSquadronException( |
| 40 | | | [String? tokenId, StackTrace? stackTrace]) => |
| 41 | | 2 | SquadronCanceledException.from( |
| 42 | | | tokenId ?? '', |
| 43 | | | this, |
| 44 | | | stackTrace, |
| 45 | | | ); |
| 46 | | | } |
| 47 | | | |
| 48 | | | @internal |
| 49 | | | extension TimeoutConversionExt on TimeoutException { |
| 50 | | 2 | SquadronException toSquadronException( |
| 51 | | | [String? tokenId, StackTrace? stackTrace]) => |
| 52 | | 2 | SquadronTimeoutException( |
| 53 | | | tokenId ?? '', |
| 54 | | 2 | message ?? 'Operation timeout', |
| 55 | | 2 | duration, |
| 56 | | | stackTrace, |
| 57 | | | ); |
| 58 | | | } |