-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwork.dylan
48 lines (40 loc) · 1.12 KB
/
work.dylan
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
38
39
40
41
42
43
44
45
46
47
48
module: concurrency
synopsis: Work items.
author: Ingo Albrecht <[email protected]>
copyright: See accompanying file LICENSE
define class <work> (<object>)
// function performing the work, must not have any required arguments
constant slot work-function :: <function>,
required-init-keyword: function:;
// if this work item has been started
slot work-started? :: <boolean> = #f;
// if this work item has been finished
slot work-finished? :: <boolean> = #f;
// thread that processed this work item
slot work-thread :: false-or(<thread>) = #f;
end class;
define generic work-start (work :: <work>)
=> ();
define generic work-finish (work :: <work>)
=> ();
define method work-perform (work :: <work>)
=> ();
work-start(work);
block ()
work-execute(work);
cleanup
work-finish(work);
end;
end method;
define method work-start (work :: <work>)
=> ();
work-thread(work) := current-thread();
work-started?(work) := #t;
end method;
define method work-finish (work :: <work>)
=> ();
work-finished?(work) := #t;
end method;
define method work-execute (work :: <work>)
work.work-function();
end method;