Created
November 14, 2013 19:29
-
-
Save danking/7472839 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 | |
| (define-syntax custodian-protect | |
| (syntax-rules () | |
| ((custodian-protect main-body ...) | |
| (let ((protection #f) | |
| (original #f)) | |
| (dynamic-wind (lambda () | |
| (set! original (current-custodian)) | |
| (set! protection (make-custodian original)) | |
| (current-custodian protection)) | |
| (lambda () main-body ...) | |
| (lambda () | |
| (custodian-shutdown-all protection) | |
| (current-custodian original))))))) | |
| (define kont | |
| (custodian-protect | |
| (call/cc (lambda (k) | |
| (thread (lambda () ((lambda (x) (begin (printf "Hey there")(x x))) | |
| (lambda (x) (begin (printf "Hey there") (sleep 1)(x x)))))) | |
| (custodian-protect | |
| (define x (open-input-file "/tmp/foo")) | |
| (define | |
| port | |
| (call/cc (lambda (k2) | |
| (k (list k2 x))))) | |
| (display (read port))) | |
| (sleep 5)(k #f))))) | |
| (define kontinuation (first kont)) | |
| (define port (second kont)) | |
| (kontinuation port) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment