adjusted the registration mechanism for planet-terse-register to be clearer and simpler
This commit is contained in:
parent
2282cae59a
commit
d879f75152
|
@ -736,30 +736,31 @@ namespace-specific.
|
||||||
@defproc[(planet-terse-register
|
@defproc[(planet-terse-register
|
||||||
[proc (-> (or/c 'download 'install 'docs-build 'finish)
|
[proc (-> (or/c 'download 'install 'docs-build 'finish)
|
||||||
string?
|
string?
|
||||||
any/c)]
|
any/c)])
|
||||||
[key symbol? (planet-terse-log-key-param)])
|
|
||||||
void?]{
|
void?]{
|
||||||
Registers @racket[proc] as a function to be called when
|
Registers @racket[proc] as a function to be called when
|
||||||
@racket[planet-terse-log] is called with a matching namespace argument.
|
@racket[planet-terse-log] is called.
|
||||||
Note that @racket[proc] is called
|
|
||||||
|
Note that @racket[proc] is called
|
||||||
asynchronously (ie, on some thread other than the one calling @racket[planet-terse-register]).
|
asynchronously (ie, on some thread other than the one calling @racket[planet-terse-register]).
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(planet-terse-log [id (or/c 'download 'install 'finish)]
|
@defproc[(planet-terse-log [id (or/c 'download 'install 'finish)]
|
||||||
[msg string?]
|
[msg string?]) void?]{
|
||||||
[key symbol? (planet-terse-log-key-param)]) void?]{
|
This function is called by PLaneT to announce when things are happening. See also
|
||||||
This function is called by PLaneT to announce when things are happening.
|
@racket[planet-terse-set-key].
|
||||||
The namespace passed along is used to identify the procs to notify. This function
|
|
||||||
invokes all of the callbacks registered with @racket[key], and when PLaneT invokes it,
|
|
||||||
the @racket[key] argument is always @racket[(planet-terse-log-key-param)].
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@defparam[planet-terse-log-key-param key symbol?]{
|
@defproc[(planet-terse-set-key [key any/c]) void?]{
|
||||||
Holds the current value of the key used for getting and setting the @PLaneT logging information.
|
This sets a @seclink["threadcells" #:doc '(lib "scribblings/reference/reference.scrbl")]{thread cell}
|
||||||
}
|
to the value of @racket[key].
|
||||||
|
The value of the thread cell is used as an index into a table to determine which
|
||||||
@defproc[(planet-terse-set-key [key symbol?]) void?]{
|
of the functions passed to @racket[planet-terse-register] to call when
|
||||||
Equivalent to @racket[(planet-terse-log-key-param new-key)].
|
@racket[planet-terse-log] is called.
|
||||||
|
|
||||||
|
The table holding the key uses ephemerons and a weak hash table to ensure that
|
||||||
|
when the @racket[key] is unreachable, then the procedures passed to @racket[planet-terse-log]
|
||||||
|
cannot be reached through the table.
|
||||||
}
|
}
|
||||||
|
|
||||||
@section{Developing Packages for PLaneT}
|
@section{Developing Packages for PLaneT}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang scheme/base
|
#lang racket/base
|
||||||
|
|
||||||
#|
|
#|
|
||||||
|
|
||||||
|
@ -14,12 +14,11 @@ seems little point to that).
|
||||||
|
|
||||||
(provide planet-terse-register
|
(provide planet-terse-register
|
||||||
planet-terse-log
|
planet-terse-log
|
||||||
planet-terse-set-key
|
planet-terse-set-key)
|
||||||
planet-terse-log-key-param)
|
|
||||||
|
|
||||||
(define terse-log-message-chan (make-channel))
|
(define terse-log-message-chan (make-channel))
|
||||||
(define terse-log-proc-chan (make-channel))
|
(define terse-log-proc-chan (make-channel))
|
||||||
(define planet-terse-log-key-param (make-parameter (gensym)))
|
(define log-key-tc (make-thread-cell (gensym) #t))
|
||||||
|
|
||||||
(define thd
|
(define thd
|
||||||
(thread
|
(thread
|
||||||
|
@ -33,30 +32,29 @@ seems little point to that).
|
||||||
(let ([registry (list-ref msg 0)]
|
(let ([registry (list-ref msg 0)]
|
||||||
[id (list-ref msg 1)]
|
[id (list-ref msg 1)]
|
||||||
[str (list-ref msg 2)])
|
[str (list-ref msg 2)])
|
||||||
(for-each (lambda (eph)
|
(for ([eph (in-list (hash-ref procs registry '()))])
|
||||||
(let ([proc (weak-box-value eph)])
|
(let ([proc (ephemeron-value eph)])
|
||||||
(when proc
|
(when proc
|
||||||
(proc id str))))
|
(proc id str)))))
|
||||||
(hash-ref procs registry '())))
|
|
||||||
(loop)))
|
(loop)))
|
||||||
(handle-evt
|
(handle-evt
|
||||||
terse-log-proc-chan
|
terse-log-proc-chan
|
||||||
(lambda (rp)
|
(lambda (rp)
|
||||||
(let ([registry (list-ref rp 0)]
|
(let* ([registry (list-ref rp 0)]
|
||||||
[proc (list-ref rp 1)])
|
[proc (list-ref rp 1)])
|
||||||
(hash-update! procs
|
(hash-update! procs
|
||||||
registry
|
registry
|
||||||
(lambda (x) (cons (make-weak-box proc) x))
|
(lambda (x) (cons (make-ephemeron registry proc) x))
|
||||||
'())
|
'())
|
||||||
(loop))))))))))
|
(loop))))))))))
|
||||||
|
|
||||||
(define (planet-terse-log id str [key (planet-terse-log-key-param)])
|
(define (planet-terse-log id str)
|
||||||
(sync (channel-put-evt terse-log-message-chan (list key id str)))
|
(sync (channel-put-evt terse-log-message-chan (list (thread-cell-ref log-key-tc) id str)))
|
||||||
(void))
|
(void))
|
||||||
|
|
||||||
(define (planet-terse-register proc [key (planet-terse-log-key-param)])
|
(define (planet-terse-register proc)
|
||||||
(sync (channel-put-evt terse-log-proc-chan (list key proc)))
|
(sync (channel-put-evt terse-log-proc-chan (list (thread-cell-ref log-key-tc) proc)))
|
||||||
(void))
|
(void))
|
||||||
|
|
||||||
(define (planet-terse-set-key new-key)
|
(define (planet-terse-set-key new-key)
|
||||||
(planet-terse-log-key-param new-key))
|
(thread-cell-set! log-key-tc new-key))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user