-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAsyncExamples.wlt
80 lines (64 loc) · 1.72 KB
/
AsyncExamples.wlt
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Needs["MUnit`"]
(* Test the async_file_watcher_raw.rs example. *)
Test[
delay = 100;
file = CreateFile[];
$changes = {};
eventHandler[
taskObject_,
"change",
{modTime_}
] := AppendTo[$changes, modTime];
(* Begin the background task. *)
task = Internal`CreateAsynchronousTask[
LibraryFunctionLoad[
"libasync_file_watcher_raw",
"start_file_watcher",
{Integer, "UTF8String"},
Integer
],
{delay, file},
eventHandler
];
(* Modify the watched file. *)
Put[1, file];
expectedModifiedTime = UnixTime[];
(* Ensure the file modification check has time to run. *)
Pause[Quantity[2 * delay, "Milliseconds"]];
StopAsynchronousTask[task];
$changes
,
{expectedModifiedTime}
]
(* Test the async_file_watcher.rs example. This is identical to the above test, except the
example implementation uses the safe wrappers. *)
Test[
delay = 100;
file = CreateFile[];
$changes2 = {};
eventHandler[
taskObject_,
"change",
{modTime_}
] := AppendTo[$changes2, modTime];
(* Begin the background task. *)
task = Internal`CreateAsynchronousTask[
LibraryFunctionLoad[
"libasync_file_watcher",
"start_file_watcher",
{Integer, "UTF8String"},
Integer
],
{delay, file},
eventHandler
];
(* Modify the watched file. *)
Put[1, file];
expectedModifiedTime = UnixTime[];
(* Ensure the file modification check has time to run. *)
Pause[Quantity[2 * delay, "Milliseconds"]];
StopAsynchronousTask[task];
$changes2
,
{expectedModifiedTime}
]