Example for os2
This commit is contained in:
parent
d17435564e
commit
4e8c0b4612
|
@ -0,0 +1,30 @@
|
|||
#lang racket/base
|
||||
;; Trivial demonstration of an os2.rkt virtual machine.
|
||||
|
||||
(require "os2.rkt")
|
||||
(require racket/pretty)
|
||||
|
||||
(define (super-alarm msecs)
|
||||
(wrap-evt (alarm-evt msecs) (lambda (_) (current-inexact-milliseconds))))
|
||||
|
||||
(define (sleep n k)
|
||||
(transition k
|
||||
(add-role (topic-subscriber (super-alarm (+ (current-inexact-milliseconds) n)))
|
||||
(handlers #f #f (lambda (eid topic now)
|
||||
(lambda (k)
|
||||
(extend-transition (k)
|
||||
(delete-role eid))))))))
|
||||
|
||||
(define (example-process delay)
|
||||
(write `(sleeping for ,delay milliseconds))
|
||||
(newline)
|
||||
(sleep delay (lambda ()
|
||||
(write `(awoke after ,delay milliseconds))
|
||||
(newline)
|
||||
(transition 'no-state (kill)))))
|
||||
|
||||
(ground-vm (lambda ()
|
||||
(transition 'no-state
|
||||
(spawn (lambda () (example-process 1000)))
|
||||
(spawn (lambda () (example-process 2000)))
|
||||
(kill))))
|
Loading…
Reference in New Issue