-
Notifications
You must be signed in to change notification settings - Fork 1
/
comtayexample.pas
65 lines (47 loc) · 1.21 KB
/
comtayexample.pas
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(******************************************************************************
This is an example using COMTAY coroutine manager.
Download COMTAY at https://opensimply.org/comtay/
*******************************************************************************)
program COMTAYexample;
{$S-}
uses
Comtay; // The Comtay unit contains coroutine functions.
type
TCotask1 = class(TCoTask)
protected
procedure Body; override;
end;
TCotask2 = class(TCoTask)
protected
procedure Body; override;
end;
procedure TCotask1.Body; // Description of Task #1.
var
i: Integer;
begin
for i := 1 to 3 do
begin
Write('Hello, ');
Resume(Cotask2);
end;
end;
procedure TCotask2.Body; // Description of Task #2.
begin
repeat
WriteLn('World!');
Suspend;
until false;
end;
var
Cotask1: TCotask1;
Cotask2: TCotask2;
begin
InitializeComtay; // Start using the COMTAY.
Cotask1 := TCotask1.Create;
Cotask2 := TCotask2.Create;
Cotask1.Start;
Cotask1.Free;
Cotask2.Free;
Write(EOL, 'Press ENTER for program termination');
ReadLn;
end.