Skip to content

Commit

Permalink
Don't encourage escape continuations with await-geteveryline!
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Vine committed Apr 25, 2016
1 parent 485db04 commit aa8e895
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 59 deletions.
9 changes: 4 additions & 5 deletions a-sync/event-loop.scm
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,10 @@
;; This procedure is implemented using a-sync-read-watch!. Unlike the
;; await-getline! procedure, the watch will continue after a line of
;; text has been received in order to receive further lines. The
;; watch will not end until end-of-file or an exceptional condition is
;; reached. In the event of that happening, this procedure will end
;; and return an end-of-file object or #f respectively. To finish
;; before end-of-file or an exceptional condition, 'proc' can invoke a
;; call/ec escape continuation.
;; watch will not end until end-of-file or an exceptional condition
;; ('excpt) is reached. In the event of that happening, this
;; procedure will end and return an end-of-file object or #f
;; respectively.
;;
;; The 'loop' argument is optional: this procedure operates on the
;; event loop passed in as an argument, or if none is passed (or #f is
Expand Down
30 changes: 13 additions & 17 deletions docs/event-loop.texi
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,9 @@ to be called in a waitable procedure invoked by a-sync, and this
procedure is implemented using a-sync-read-watch!. Unlike the
await-getline! procedure, the watch will continue after a line of text
has been received in order to receive further lines. The watch will
not end until end-of-file or an exceptional condition is reached. In
the event of that happening, this procedure will end and return an
end-of-file object or #f respectively. To finish before end-of-file
or an exceptional condition, 'proc' can invoke a call/ec escape
continuation.
not end until end-of-file or an exceptional condition ('excpt) is
reached. In the event of that happening, this procedure will end and
return an end-of-file object or #f respectively.

The 'loop' argument is optional: this procedure operates on the event
loop passed in as an argument, or if none is passed (or #f is passed),
Expand All @@ -473,21 +471,19 @@ setting up (that is, before the first call to 'await' is made), which
shouldn't happen unless memory is exhausted. Subsequent exceptions
(say, because of port errors) will propagate out of event-loop-run!.

Here is an example of the use of await-geteveryline!:
Here is an example of the use of await-geteveryline! (because the
keyboard has no end-of-file, use Ctrl-C to exit this code snippet):
@example
(set-default-event-loop!) ;; if none has yet been set
(a-sync (lambda (await resume)
(display "Enter lines of text at the keyboard, enter empty line to finish\n")
(call/ec (lambda (k)
(await-geteveryline! await resume
(open "/dev/tty" O_RDONLY)
(lambda (line)
(when (string=? line "")
(k #f))
(simple-format #t
"The line was: ~A\n"
line)))))
(event-loop-quit!)))
(display "Enter lines of text at the keyboard, ^C to finish\n")
(let ((port (open "/dev/tty" O_RDONLY)))
(await-geteveryline! await resume
port
(lambda (line)
(simple-format #t
"The line was: ~A\n"
line))))))
(event-loop-run!)
@end example
@end deffn
Expand Down
37 changes: 17 additions & 20 deletions docs/guile-a-sync.info
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,10 @@ thread.
and this procedure is implemented using a-sync-read-watch!. Unlike
the await-getline! procedure, the watch will continue after a line
of text has been received in order to receive further lines. The
watch will not end until end-of-file or an exceptional condition is
reached. In the event of that happening, this procedure will end
and return an end-of-file object or #f respectively. To finish
before end-of-file or an exceptional condition, 'proc' can invoke a
call/ec escape continuation.
watch will not end until end-of-file or an exceptional condition
('excpt) is reached. In the event of that happening, this
procedure will end and return an end-of-file object or #f
respectively.

The 'loop' argument is optional: this procedure operates on the
event loop passed in as an argument, or if none is passed (or #f is
Expand All @@ -754,20 +753,18 @@ thread.
exceptions (say, because of port errors) will propagate out of
event-loop-run!.

Here is an example of the use of await-geteveryline!:
Here is an example of the use of await-geteveryline! (because the
keyboard has no end-of-file, use Ctrl-C to exit this code snippet):
(set-default-event-loop!) ;; if none has yet been set
(a-sync (lambda (await resume)
(display "Enter lines of text at the keyboard, enter empty line to finish\n")
(call/ec (lambda (k)
(await-geteveryline! await resume
(open "/dev/tty" O_RDONLY)
(lambda (line)
(when (string=? line "")
(k #f))
(simple-format #t
"The line was: ~A\n"
line)))))
(event-loop-quit!)))
(display "Enter lines of text at the keyboard, ^C to finish\n")
(let ((port (open "/dev/tty" O_RDONLY)))
(await-geteveryline! await resume
port
(lambda (line)
(simple-format #t
"The line was: ~A\n"
line))))))
(event-loop-run!)

-- Scheme Procedure: a-sync-write-watch! resume file proc [loop]
Expand Down Expand Up @@ -1222,8 +1219,8 @@ Tag Table:
Node: Top85
Node: coroutines1099
Node: event loop14941
Node: monotonic time42148
Node: gnome glib43582
Node: compose57361
Node: monotonic time41996
Node: gnome glib43430
Node: compose57209

End Tag Table
30 changes: 13 additions & 17 deletions docs/html/event-loop.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa8e895

Please sign in to comment.