Skip to content

Instantly share code, notes, and snippets.

@torus
Last active March 19, 2020 03:34
Show Gist options
  • Save torus/8ce22c67e6ae93286d92a742f481afba to your computer and use it in GitHub Desktop.
Save torus/8ce22c67e6ae93286d92a742f481afba to your computer and use it in GitHub Desktop.
(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*))))
version: '3'
services:
gosh:
image: practicalscheme/gauche
volumes:
- .:/work
working_dir: /work
@torus
Copy link
Author

torus commented Mar 18, 2020

@torus
Copy link
Author

torus commented Mar 19, 2020

query は非同期に応答を返す何かのシミュレーション。
on-dataon-end はデータを受け取った時に呼び出されるハンドラ。

query-cont が継続を使ったラッパー。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment