forked from ojwoodford/batch_job
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onCleanup_.m
37 lines (32 loc) · 971 Bytes
/
onCleanup_.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
classdef onCleanup_ < handle
properties(SetAccess = 'private', GetAccess = 'public', Transient)
task_list = cell(0);
end
methods
function this = onCleanup_(func)
this.task_list{1} = func;
end
function delete(this)
for a = 1:numel(this.task_list)
try
this.task_list{a}();
catch me
warning(getReport(me, 'extended', 'hyperlinks', 'on'));
end
end
end
function append(this, func)
this.task_list{end+1} = func;
end
function prepend(this, func)
this.task_list = [{func}; this.task_list(:)];
end
function replace(this, func, ind)
if nargin < 3
this.task_list = {func};
else
this.task_list{ind} = func;
end
end
end
end