From 2e05917df38aa2be0fd697d8561e0cb009396e06 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Sun, 28 Jul 2024 23:25:12 +0200 Subject: [PATCH] Added "Always" callback in the MVCAsync --- sources/MVCFramework.AsyncTask.pas | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/sources/MVCFramework.AsyncTask.pas b/sources/MVCFramework.AsyncTask.pas index f161ebf7..67c7ce1f 100644 --- a/sources/MVCFramework.AsyncTask.pas +++ b/sources/MVCFramework.AsyncTask.pas @@ -34,6 +34,7 @@ type TMVCAsyncBackgroundTask = reference to function: T; TMVCAsyncSuccessCallback = reference to procedure(const BackgroundTaskResult: T); TMVCAsyncErrorCallback = reference to procedure(const Expt: Exception); + TMVCAsyncAlwaysCallback = reference to procedure; TMVCAsyncDefaultErrorCallback = reference to procedure(const Expt: Exception; const ExptAddress: Pointer); @@ -42,7 +43,8 @@ type class function Run( Task: TMVCAsyncBackgroundTask; Success: TMVCAsyncSuccessCallback; - Error: TMVCAsyncErrorCallback = nil): ITask; + Error: TMVCAsyncErrorCallback = nil; + Always: TMVCAsyncAlwaysCallback = nil): ITask; end; var @@ -66,7 +68,8 @@ uses class function MVCAsync.Run( Task: TMVCAsyncBackgroundTask; Success: TMVCAsyncSuccessCallback; - Error: TMVCAsyncErrorCallback): ITask; + Error: TMVCAsyncErrorCallback; + Always: TMVCAsyncAlwaysCallback): ITask; var LRes: T; begin @@ -98,14 +101,26 @@ begin LCurrException := Exception(Ex); try if Assigned(Error) then - Error(LCurrException) + begin + Error(LCurrException); + end else + begin gDefaultTaskErrorHandler(LCurrException, ExceptionAddress); + end; finally FreeAndNil(LCurrException); end; end); end; + if Assigned(Always) then + begin + TThread.Queue(nil, + procedure + begin + Always(); + end); + end; end); end;