1coroutine(n)                  Coroutine utilities                 coroutine(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       coroutine - Coroutine based event and IO handling
9

SYNOPSIS

11       package require Tcl  8.6
12
13       package require coroutine  1.3
14
15       coroutine::util after delay
16
17       coroutine::util await varname...
18
19       coroutine::util create arg...
20
21       coroutine::util exit ?status?
22
23       coroutine::util gets chan ?varname?
24
25       coroutine::util gets_safety chan limit varname
26
27       coroutine::util global varname...
28
29       coroutine::util puts ?-nonewline? channel string
30
31       coroutine::util read -nonewline chan ?n?
32
33       coroutine::util socket ?options...? host port
34
35       coroutine::util update ?idletasks?
36
37       coroutine::util vwait varname
38
39______________________________________________________________________________
40

DESCRIPTION

42       The coroutine package provides coroutine-aware implementations of vari‐
43       ous event- and channel related commands. It can be in multiple modes:
44
45       [1]    Call the commands through their ensemble, in code which  is  ex‐
46              plicitly written for use within coroutines.
47
48       [2]    Import  the  commands  into  a  namespace,  either  directly, or
49              through namespace path. This allows the  use  from  within  code
50              which  is  not coroutine-aware per se and restricted to specific
51              namespaces.
52
53       A more agressive form of making code coroutine-oblivious than  point  2
54       above  is  available  through the package coroutine::auto, which inter‐
55       cepts the relevant builtin commands and  changes  their  implementation
56       dependending on the context they are run in, i.e.  inside or outside of
57       a coroutine.
58

API

60       All the commands listed below  are  synchronous  with  respect  to  the
61       coroutine invoking them, i.e. this coroutine blocks until the result is
62       available. The overall eventloop is not blocked however.
63
64       coroutine::util after delay
65              This command delays the coroutine invoking it by delay millisec‐
66              onds.
67
68       coroutine::util await varname...
69              This  command  is an extension form of the coroutine::util vwait
70              command (see below) which waits on a write to one of many  named
71              namespace variables.
72
73       coroutine::util create arg...
74              This  command  creates a new coroutine with an automatically as‐
75              signed name and causes it to run the code specified by the argu‐
76              ments.
77
78       coroutine::util exit ?status?
79              This  command  exits the current coroutine, causing it to return
80              status. If no status was specified the default 0 is returned.
81
82       coroutine::util gets chan ?varname?
83              This command reads a line from the channel chan and  returns  it
84              either  as its result, or, if a varname was specified, writes it
85              to the named variable and returns the number of characters read.
86
87       coroutine::util gets_safety chan limit varname
88              This command reads a line from the channel chan up to size limit
89              and stores the result in varname. Of limit is reached before the
90              set first newline, an error is thrown. The command  returns  the
91              number of characters read.
92
93       coroutine::util global varname...
94              This command imports the named global variables of the coroutine
95              into the current scope. From the technical point of  view  these
96              variables  reside  in  level #1 of the Tcl stack. I.e. these are
97              not the regular global variable in to the global namespace,  and
98              each  coroutine  can have their own set, independent of all oth‐
99              ers.
100
101       coroutine::util puts ?-nonewline? channel string
102              This commands writes the string to the specified channel.   Con‐
103              trary  to  the builtin puts this command waits until the channel
104              is writable before actually writing to it.
105
106       coroutine::util read -nonewline chan ?n?
107              This command reads n characters from the channel  chan  and  re‐
108              turns them as its result. If n is not specified the command will
109              read the channel until EOF is reached.
110
111       coroutine::util socket ?options...? host port
112              This command connects to the specified host and port and returns
113              when that is done. Contrary to the builtin command it performs a
114              non-blocking connect in  the  background.  As  such,  while  its
115              blocks  the  calling  coroutine,  the overall application is not
116              blocked.
117
118       coroutine::util update ?idletasks?
119              This command causes the coroutine invoking  it  to  run  pending
120              events or idle handlers before proceeding.
121
122       coroutine::util vwait varname
123              This command causes the coroutine calling it to wait for a write
124              to the named namespace variable varname.
125

BUGS, IDEAS, FEEDBACK

127       This document, and the package it describes, will  undoubtedly  contain
128       bugs  and other problems.  Please report such in the category coroutine
129       of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].   Please
130       also  report any ideas for enhancements you may have for either package
131       and/or documentation.
132
133       When proposing code changes, please provide unified diffs, i.e the out‐
134       put of diff -u.
135
136       Note  further  that  attachments  are  strongly  preferred over inlined
137       patches. Attachments can be made by going  to  the  Edit  form  of  the
138       ticket  immediately  after  its  creation, and then using the left-most
139       button in the secondary navigation bar.
140

KEYWORDS

142       after, channel, coroutine, events, exit, gets, global,  green  threads,
143       read, threads, update, vwait
144

CATEGORY

146       Coroutine
147
149       Copyright (c) 2010-2015 Andreas Kupries <andreas_kupries@users.sourceforge.net>
150
151
152
153
154tcllib                                1.3                         coroutine(n)
Impressum