This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
forked from jeapostrophe/racket-langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue-only-latest.rkt
55 lines (47 loc) · 1.59 KB
/
queue-only-latest.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
44
45
46
47
48
49
50
51
52
53
54
55
#lang racket/base
(require racket/match
framework
racket/class
"debug.rkt"
"check-syntax.rkt"
"interfaces.rkt")
(define (do-check-and-stuff! data)
(match-define (list src text doc) data)
(define new-text (new racket:text%))
(send new-text insert text)
(define new-trace (check-syntax src new-text (doc-trace doc)))
(set-doc-trace! doc new-trace))
(define (waiter in-ch ready-ch out-ch)
(define (run doc ready?)
(define (send-doc! doc)
(channel-put out-ch doc)
(run #f #f))
(sync (handle-evt in-ch
(lambda (doc)
(cond
[ready? (send-doc! doc)]
[else (run doc #f)])))
(handle-evt ready-ch
(lambda (ignore)
(cond
[doc (send-doc! doc)]
[else (run #f #t)])))))
(run #f #t))
(define (check in-ch ready-ch)
(define (run)
(define doc (sync in-ch))
(do-check-and-stuff! doc)
(channel-put ready-ch #t)
(run))
(run))
(define in-ch (make-channel))
(define ready-ch (make-channel))
(define wait->check (make-channel))
(define waiter-th (thread (lambda () (waiter in-ch ready-ch wait->check))))
(define server-th (thread (lambda () (check wait->check ready-ch))))
(define (try-queue-check src doc)
(when (and (thread-running? waiter-th) (thread-running? server-th))
(define txt (send (doc-text doc) get-text))
(maybe-debug-file txt)
(channel-put in-ch (list src txt doc))))
(provide try-queue-check)