Created
May 22, 2019 15:42
-
-
Save greghendershott/731d20f55288cee6237b0dff3676a6bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require racket/require | |
(multi-in racket (contract function))) | |
(define executor (make-will-executor)) | |
(void (thread (λ () (let loop () (will-execute executor) (loop))))) | |
(define frame? any/c) | |
(define/contract (make-framing-channel in read-frame) | |
(-> input-port? (-> input-port? (or/c frame? exn?)) | |
(or/c frame? exn?)) | |
(define ch (make-channel)) | |
(define (framing-thread-thunk) | |
(with-handlers ([(const #t) (curry channel-put ch)]) | |
(for ([v (in-port read-frame in)]) | |
(channel-put ch v)) | |
(channel-put ch eof))) | |
(define framing-thread (thread framing-thread-thunk)) | |
(will-register executor ch (λ (_) (break-thread framing-thread))) | |
ch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment