-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.rkt
43 lines (36 loc) · 1.34 KB
/
watch.rkt
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
#lang typed/racket/base
(require racket/system
racket/file)
(module wrapper-file-watchers racket/base
(require file-watchers)
(provide apathetic-watch
file-activity-channel
file-watcher-channel-get
file-watcher-status-channel
path-on-disk?
suggest-approach
watch))
(require/typed 'wrapper-file-watchers
[#:opaque Path-On-Disk path-on-disk?]
[apathetic-watch (-> Path Thread)]
[file-activity-channel (Parameter (Async-Channelof Any))]
[file-watcher-channel-get (-> (U Boolean (Listof Any)))]
[file-watcher-status-channel (Parameter (Async-Channelof Any))]
[watch (->* ()
((Listof Path) ; paths
(-> (Listof Any) Any) ; on-activity
(-> (Listof Any) Any) ; on-status
(-> Path Thread))
Thread)])
(define paths (list (string->path "pong.rkt") (string->path "lib/")))
(: thread-box (Boxof (U Thread #f)))
(define thread-box (box #f))
(let loop ()
(define unboxed-thread (unbox thread-box))
(if unboxed-thread (kill-thread unboxed-thread) '())
(define new-thread (watch paths
(lambda (lst) (system "raco make pong.rkt && racket pong.rkt"))
(lambda (lst) '())))
(box-cas! thread-box unboxed-thread new-thread)
(thread-wait new-thread)
(loop))