mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Added "Always" callback in the MVCAsync
This commit is contained in:
parent
b422dc610e
commit
2e05917df3
@ -34,6 +34,7 @@ type
|
||||
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);
|
||||
|
||||
@ -42,7 +43,8 @@ type
|
||||
class function Run<T>(
|
||||
Task: TMVCAsyncBackgroundTask<T>;
|
||||
Success: TMVCAsyncSuccessCallback<T>;
|
||||
Error: TMVCAsyncErrorCallback = nil): ITask;
|
||||
Error: TMVCAsyncErrorCallback = nil;
|
||||
Always: TMVCAsyncAlwaysCallback = nil): ITask;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -66,7 +68,8 @@ uses
|
||||
class function MVCAsync.Run<T>(
|
||||
Task: TMVCAsyncBackgroundTask<T>;
|
||||
Success: TMVCAsyncSuccessCallback<T>;
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user