Last active
March 19, 2020 03:34
-
-
Save torus/8ce22c67e6ae93286d92a742f481afba to your computer and use it in GitHub Desktop.
This file contains 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
(use gauche.threads) | |
(use data.queue) | |
(define *queue* (make-mtqueue)) | |
(define (query) | |
(let ((th (make-thread | |
(^[] | |
(let loop ((n 5)) | |
(if (> n 0) | |
(begin | |
(thread-sleep! 1) | |
(enqueue/wait! *queue* (^[] (on-data n))) | |
(loop (- n 1))) | |
(begin | |
(enqueue/wait! *queue* on-end) | |
(enqueue/wait! *queue* 'done)))))))) | |
(thread-start! th) | |
th)) | |
(define *sum* 0) | |
(define (on-data x) | |
(set! *sum* (+ *sum* x)) | |
(print #"Data received ~x")) | |
(define (on-end) | |
(print (* *sum* *sum*)) | |
(print "End")) | |
(query) | |
(let loop ((task (dequeue/wait! *queue*))) | |
(unless (eq? task 'done) | |
(task) | |
(loop (dequeue/wait! *queue*)))) |
This file contains 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
version: '3' | |
services: | |
gosh: | |
image: practicalscheme/gauche | |
volumes: | |
- .:/work | |
working_dir: /work |
query
は非同期に応答を返す何かのシミュレーション。
on-data
と on-end
はデータを受け取った時に呼び出されるハンドラ。
query-cont
が継続を使ったラッパー。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/torus/8ce22c67e6ae93286d92a742f481afba/90f62668e5d99bd33794bc5b182de816827883de
オリジナルのコード。