Skip to content

Instantly share code, notes, and snippets.

@greghendershott
Created May 22, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghendershott/731d20f55288cee6237b0dff3676a6bb to your computer and use it in GitHub Desktop.
Save greghendershott/731d20f55288cee6237b0dff3676a6bb to your computer and use it in GitHub Desktop.
#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