Split out reloader-mixin and reloader-mixin*
This commit is contained in:
parent
d9905df4e5
commit
b87639b7a4
|
@ -7,7 +7,9 @@
|
|||
|
||||
stop-when-reloaded
|
||||
spawn-reloader
|
||||
spawn-reloader*)
|
||||
spawn-reloader*
|
||||
reloader-mixin
|
||||
reloader-mixin*)
|
||||
|
||||
(define-logger syndicate/reload)
|
||||
|
||||
|
@ -36,13 +38,32 @@
|
|||
(spawn-reloader* 'module-path))
|
||||
|
||||
(define (spawn-reloader* module-path)
|
||||
(match (module-path->path-string module-path)
|
||||
[#f #f]
|
||||
[pathstr
|
||||
(supervise #:name (list 'reloader-supervisor pathstr)
|
||||
(actor #:name 'reloader
|
||||
(reloader-mixin** module-path pathstr)))
|
||||
#t]))
|
||||
|
||||
(define-syntax-rule (reloader-mixin module-path)
|
||||
(reloader-mixin* 'module-path))
|
||||
|
||||
(define (reloader-mixin* module-path)
|
||||
(define pathstr (module-path->path-string module-path))
|
||||
(when (not pathstr)
|
||||
(error 'reloader-mixin "Cannot deduce source path from module-path ~v" module-path))
|
||||
(reloader-mixin** module-path pathstr))
|
||||
|
||||
(define (module-path->path-string module-path)
|
||||
(define mpi (module-path-index-join module-path #f))
|
||||
(define rpath (module-path-index-resolve mpi))
|
||||
(define path (let ((p (resolved-module-path-name rpath)))
|
||||
(if (pair? p) (car p) p)))
|
||||
(if (path? path)
|
||||
(spawn-reloader** module-path (path->string path))
|
||||
(log-syndicate/reload-error "Could not process module-path ~v" module-path)))
|
||||
(path->string path)
|
||||
(begin (log-syndicate/reload-error "Could not process module-path ~v" module-path)
|
||||
#f)))
|
||||
|
||||
(define counter
|
||||
(let ((count 0))
|
||||
|
@ -50,9 +71,7 @@
|
|||
(begin0 count
|
||||
(set! count (+ count 1))))))
|
||||
|
||||
(define (spawn-reloader** module-path pathstr)
|
||||
(supervise #:name (list 'reloader-supervisor pathstr)
|
||||
(actor #:name 'reloader
|
||||
(define (reloader-mixin** module-path pathstr)
|
||||
(field [reloading? #f])
|
||||
(define (reload!)
|
||||
(when (not (reloading?))
|
||||
|
@ -81,4 +100,4 @@
|
|||
(if (latest-version)
|
||||
(reload!)
|
||||
(log-syndicate/reload-warning "Module ~v does not exist" pathstr))
|
||||
(previous-version (latest-version)))))))
|
||||
(previous-version (latest-version)))))
|
||||
|
|
Loading…
Reference in New Issue