Skip to content

Commit

Permalink
Added "Always" callback in the MVCAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Jul 28, 2024
1 parent b422dc6 commit 2e05917
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions sources/MVCFramework.AsyncTask.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface
TMVCAsyncBackgroundTask<T> = reference to function: T;
TMVCAsyncSuccessCallback<T> = 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);

Expand All @@ -42,7 +43,8 @@ MVCAsync = class sealed
class function Run<T>(
Task: TMVCAsyncBackgroundTask<T>;
Success: TMVCAsyncSuccessCallback<T>;
Error: TMVCAsyncErrorCallback = nil): ITask;
Error: TMVCAsyncErrorCallback = nil;
Always: TMVCAsyncAlwaysCallback = nil): ITask;
end;

var
Expand All @@ -66,7 +68,8 @@ implementation
class function MVCAsync.Run<T>(
Task: TMVCAsyncBackgroundTask<T>;
Success: TMVCAsyncSuccessCallback<T>;
Error: TMVCAsyncErrorCallback): ITask;
Error: TMVCAsyncErrorCallback;
Always: TMVCAsyncAlwaysCallback): ITask;
var
LRes: T;
begin
Expand Down Expand Up @@ -98,14 +101,26 @@ class function MVCAsync.Run<T>(
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;

Expand Down

0 comments on commit 2e05917

Please sign in to comment.