Big refactor for 8sync on fibers in progress.
[8sync.git] / demos / actors / simplest-possible.scm
1 ;;; 8sync --- Asynchronous programming for Guile
2 ;;; Copyright © 2016, 2017 Christopher Allan Webber <cwebber@dustycloud.org>
3 ;;;
4 ;;; This file is part of 8sync.
5 ;;;
6 ;;; 8sync is free software: you can redistribute it and/or modify it
7 ;;; under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation, either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; 8sync is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU Lesser General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with 8sync.  If not, see <http://www.gnu.org/licenses/>.
18
19 (use-modules (8sync actors)
20              (oop goops)
21              (fibers conditions))
22
23 (define-actor <emo> (<actor>)
24   ((greet-proog
25     (lambda (actor message target)
26       (display "emo> What's next, Proog?\n")
27       (<- target 'greet-emo)))))
28
29 (define-actor <proog> (<actor>)
30   ((greet-emo
31     (lambda (actor message)
32       (display "proog> Listen, Emo!  Listen to the sounds of the machine!\n")
33       (signal-condition! (.done? actor)))))
34   (done? #:init-keyword #:done?
35          #:accessor .done?))
36
37 (define (main . args)
38   (run-hive
39    (lambda (hive)
40      (define done? (make-condition))
41      (define our-emo (bootstrap-actor hive <emo>))
42      (define our-proog (bootstrap-actor hive <proog>
43                                         #:done? done?))
44      (<- our-emo 'greet-proog our-proog)
45      (wait done?))))