This file is indexed.

/usr/share/doc/liblwt-ocaml-dev/api/Lwt.html is in liblwt-ocaml-doc 2.3.1-1build3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="previous" href="Lwt_list.html">
<link rel="next" href="Lwt_mutex.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of class attributes" rel=Appendix href="index_attributes.html">
<link title="Index of class methods" rel=Appendix href="index_methods.html">
<link title="Index of classes" rel=Appendix href="index_classes.html">
<link title="Index of class types" rel=Appendix href="index_class_types.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Lwt_condition" rel="Chapter" href="Lwt_condition.html">
<link title="Lwt_list" rel="Chapter" href="Lwt_list.html">
<link title="Lwt" rel="Chapter" href="Lwt.html">
<link title="Lwt_mutex" rel="Chapter" href="Lwt_mutex.html">
<link title="Lwt_mvar" rel="Chapter" href="Lwt_mvar.html">
<link title="Lwt_pool" rel="Chapter" href="Lwt_pool.html">
<link title="Lwt_sequence" rel="Chapter" href="Lwt_sequence.html">
<link title="Lwt_stream" rel="Chapter" href="Lwt_stream.html">
<link title="Lwt_switch" rel="Chapter" href="Lwt_switch.html">
<link title="Lwt_util" rel="Chapter" href="Lwt_util.html">
<link title="Lwt_pqueue" rel="Chapter" href="Lwt_pqueue.html">
<link title="Lwt_lib" rel="Chapter" href="Lwt_lib.html">
<link title="Lwt_glib" rel="Chapter" href="Lwt_glib.html">
<link title="Lwt_preemptive" rel="Chapter" href="Lwt_preemptive.html">
<link title="Lwt_event" rel="Chapter" href="Lwt_event.html">
<link title="Lwt_signal" rel="Chapter" href="Lwt_signal.html">
<link title="Lwt_react" rel="Chapter" href="Lwt_react.html">
<link title="Lwt_ssl" rel="Chapter" href="Lwt_ssl.html">
<link title="Lwt_text" rel="Chapter" href="Lwt_text.html">
<link title="Lwt_term" rel="Chapter" href="Lwt_term.html">
<link title="Lwt_read_line" rel="Chapter" href="Lwt_read_line.html">
<link title="Lwt_top" rel="Chapter" href="Lwt_top.html">
<link title="Lwt_chan" rel="Chapter" href="Lwt_chan.html">
<link title="Lwt_daemon" rel="Chapter" href="Lwt_daemon.html">
<link title="Lwt_gc" rel="Chapter" href="Lwt_gc.html">
<link title="Lwt_io" rel="Chapter" href="Lwt_io.html">
<link title="Lwt_log" rel="Chapter" href="Lwt_log.html">
<link title="Lwt_main" rel="Chapter" href="Lwt_main.html">
<link title="Lwt_process" rel="Chapter" href="Lwt_process.html">
<link title="Lwt_throttle" rel="Chapter" href="Lwt_throttle.html">
<link title="Lwt_timeout" rel="Chapter" href="Lwt_timeout.html">
<link title="Lwt_unix" rel="Chapter" href="Lwt_unix.html">
<link title="Lwt_sys" rel="Chapter" href="Lwt_sys.html">
<link title="Lwt_engine" rel="Chapter" href="Lwt_engine.html">
<link title="Lwt_bytes" rel="Chapter" href="Lwt_bytes.html">
<link title="Pa_lwt" rel="Chapter" href="Pa_lwt.html">
<link title="Pa_lwt_log" rel="Chapter" href="Pa_lwt_log.html"><link title="Definitions and basics" rel="Section" href="#6_Definitionsandbasics">
<link title="Thread storage" rel="Section" href="#6_Threadstorage">
<link title="Exceptions handling" rel="Section" href="#6_Exceptionshandling">
<link title="Multi-threads composition" rel="Section" href="#6_Multithreadscomposition">
<link title="Sleeping and resuming" rel="Section" href="#6_Sleepingandresuming">
<link title="Threads state" rel="Section" href="#6_Threadsstate">
<link title="Cancelable threads" rel="Section" href="#6_Cancelablethreads">
<link title="Pause" rel="Section" href="#6_Pause">
<link title="Misc" rel="Section" href="#6_Misc">
<title>Lwt</title>
</head>
<body>
<div class="navbar"><a href="Lwt_list.html">Previous</a>
&nbsp;<a href="index.html">Up</a>
&nbsp;<a href="Lwt_mutex.html">Next</a>
</div>
<center><h1>Module <a href="type_Lwt.html">Lwt</a></h1></center>
<br>
<pre><span class="keyword">module</span> Lwt: <code class="code"><span class="keyword">sig</span></code> <a href="Lwt.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>Module <code class="code"><span class="constructor">Lwt</span></code>: cooperative light-weight threads.<br>
<hr width="100%">
<br>
This module defines <em>cooperative light-weight threads</em> with
    their primitives. A <em>light-weight thread</em> represent a
    computation that may be not terminated, for example because it is
    waiting for some event to happen.
<p>

    Lwt threads are cooperative in the sense that switching to another
    thread is awlays explicit (with <a href="Lwt.html#VALwakeup"><code class="code"><span class="constructor">Lwt</span>.wakeup</code></a> or <code class="code">wekup_exn</code>). When a
    thread is running, it executes as much as possible, and then
    returns (a value or an eror) or sleeps.
<p>

    Note that inside a Lwt thread, exceptions must be raised with
    <a href="Lwt.html#VALfail"><code class="code"><span class="constructor">Lwt</span>.fail</code></a> instead of <code class="code">raise</code>. Also the <code class="code"><span class="keyword">try</span> ... <span class="keyword">with</span> ...</code>
    construction will not catch Lwt errors. You must use <a href="Lwt.html#VALcatch"><code class="code"><span class="constructor">Lwt</span>.catch</code></a>
    instead.
<p>

    Lwt also provides the syntax extension <a href="Pa_lwt.html"><code class="code"><span class="constructor">Pa_lwt</span></code></a> to make code
    using Lwt more readable.<br>
<br>
<span id="6_Definitionsandbasics"><h6>Definitions and basics</h6></span><br>
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">+'a</code> t</span> </pre>
<div class="info">
The type of threads returning a result of type <code class="code"><span class="keywordsign">'</span>a</code>.<br>
</div>

<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">return e</code> is a thread whose return value is the value of the
      expression <code class="code">e</code>.<br>
</div>
<pre><span id="VALfail"><span class="keyword">val</span> fail</span> : <code class="type">exn -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">fail e</code> is a thread that fails with the exception <code class="code">e</code>.<br>
</div>
<pre><span id="VALbind"><span class="keyword">val</span> bind</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> ('a -> 'b <a href="Lwt.html#TYPEt">t</a>) -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">bind t f</code> is a thread which first waits for the thread <code class="code">t</code> to
      terminate and then, if the thread succeeds, behaves as the
      application of function <code class="code">f</code> to the return value of <code class="code">t</code>.  If the
      thread <code class="code">t</code> fails, <code class="code">bind t f</code> also fails, with the same
      exception.
<p>

      The expression <code class="code">bind t (<span class="keyword">fun</span> x <span class="keywordsign">-&gt;</span> t')</code> can intuitively be read as
      <code class="code"><span class="keyword">let</span> x = t <span class="keyword">in</span> t'</code>, and if you use the <em>lwt.syntax</em> syntax
      extension, you can write a bind operation like that: <code class="code">lwt x = t <span class="keyword">in</span> t'</code>.
<p>

      Note that <code class="code">bind</code> is also often used just for synchronization
      purpose: <code class="code">t'</code> will not execute before <code class="code">t</code> is terminated.
<p>

      The result of a thread can be bound several time.<br>
</div>
<pre><span id="VAL(>>=)"><span class="keyword">val</span> (&gt;&gt;=)</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> ('a -> 'b <a href="Lwt.html#TYPEt">t</a>) -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">t &gt;&gt;= f</code> is an alternative notation for <code class="code">bind t f</code>.<br>
</div>
<pre><span id="VAL(=<<)"><span class="keyword">val</span> (=&lt;&lt;)</span> : <code class="type">('a -> 'b <a href="Lwt.html#TYPEt">t</a>) -> 'a <a href="Lwt.html#TYPEt">t</a> -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">f =&lt;&lt; t</code> is <code class="code">t &gt;&gt;= f</code><br>
</div>
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'a <a href="Lwt.html#TYPEt">t</a> -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">map f m</code> map the result of a thread. This is the same as <code class="code">bind
      m (<span class="keyword">fun</span> x <span class="keywordsign">-&gt;</span> return (f x))</code><br>
</div>
<pre><span id="VAL(>|=)"><span class="keyword">val</span> (&gt;|=)</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> ('a -> 'b) -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">m &gt;|= f</code> is <code class="code">map f m</code><br>
</div>
<pre><span id="VAL(=|<)"><span class="keyword">val</span> (=|&lt;)</span> : <code class="type">('a -> 'b) -> 'a <a href="Lwt.html#TYPEt">t</a> -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">f =|&lt; m</code> is <code class="code">map f m</code><br>
</div>
<br>
<span id="6_Threadstorage"><h6>Thread storage</h6></span><br>
<pre><span id="TYPEkey"><span class="keyword">type</span> <code class="type">'a</code> key</span> </pre>
<div class="info">
Type of a key. Keys are used to store local values into
      threads<br>
</div>

<pre><span id="VALnew_key"><span class="keyword">val</span> new_key</span> : <code class="type">unit -> 'a <a href="Lwt.html#TYPEkey">key</a></code></pre><div class="info">
<code class="code">new_key ()</code> creates a new key.<br>
</div>
<pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type">'a <a href="Lwt.html#TYPEkey">key</a> -> 'a option</code></pre><div class="info">
<code class="code">get key</code> returns the value associated with <code class="code">key</code> in the current
      thread.<br>
</div>
<pre><span id="VALwith_value"><span class="keyword">val</span> with_value</span> : <code class="type">'a <a href="Lwt.html#TYPEkey">key</a> -> 'a option -> (unit -> 'b) -> 'b</code></pre><div class="info">
<code class="code">with_value key value f</code> executes <code class="code">f</code> with <code class="code">value</code> associated to
      <code class="code">key</code>. The previous value associated to <code class="code">key</code> is restored after
      <code class="code">f</code> terminates.<br>
</div>
<br>
<span id="6_Exceptionshandling"><h6>Exceptions handling</h6></span><br>
<pre><span id="VALcatch"><span class="keyword">val</span> catch</span> : <code class="type">(unit -> 'a <a href="Lwt.html#TYPEt">t</a>) -> (exn -> 'a <a href="Lwt.html#TYPEt">t</a>) -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">catch t f</code> is a thread that behaves as the thread <code class="code">t ()</code> if
      this thread succeeds.  If the thread <code class="code">t ()</code> fails with some
      exception, <code class="code">catch t f</code> behaves as the application of <code class="code">f</code> to this
      exception.<br>
</div>
<pre><span id="VALtry_bind"><span class="keyword">val</span> try_bind</span> : <code class="type">(unit -> 'a <a href="Lwt.html#TYPEt">t</a>) -> ('a -> 'b <a href="Lwt.html#TYPEt">t</a>) -> (exn -> 'b <a href="Lwt.html#TYPEt">t</a>) -> 'b <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">try_bind t f g</code> behaves as <code class="code">bind (t ()) f</code> if <code class="code">t</code> does not
      fail.  Otherwise, it behaves as the application of <code class="code">g</code> to the
      exception associated to <code class="code">t ()</code>.<br>
</div>
<pre><span id="VALfinalize"><span class="keyword">val</span> finalize</span> : <code class="type">(unit -> 'a <a href="Lwt.html#TYPEt">t</a>) -> (unit -> unit <a href="Lwt.html#TYPEt">t</a>) -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">finalize f g</code> returns the same result as <code class="code">f ()</code> whether it
      fails or not. In both cases, <code class="code">g ()</code> is executed after <code class="code">f</code>.<br>
</div>
<br>
<span id="6_Multithreadscomposition"><h6>Multi-threads composition</h6></span><br>
<pre><span id="VALchoose"><span class="keyword">val</span> choose</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> list -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">choose l</code> behaves as the first thread in <code class="code">l</code> to terminate.  If
      several threads are already terminated, one is choosen at
      random.
<p>

      Note: <a href="Lwt.html#VALchoose"><code class="code"><span class="constructor">Lwt</span>.choose</code></a> leaves the local values of the current thread
      unchanged.<br>
</div>
<pre><span id="VALnchoose"><span class="keyword">val</span> nchoose</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> list -> 'a list <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">nchoose l</code> returns the value of all that have succcessfully
      terminated. If all threads are sleeping, it waits for at least
      one to terminates. If one the threads of <code class="code">l</code> fails, <code class="code">nchoose</code>
      fails with the same exception.
<p>

      Note: <a href="Lwt.html#VALnchoose"><code class="code"><span class="constructor">Lwt</span>.nchoose</code></a> leaves the local values of the current thread
      unchanged.<br>
</div>
<pre><span id="VALnchoose_split"><span class="keyword">val</span> nchoose_split</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> list -> ('a list * 'a <a href="Lwt.html#TYPEt">t</a> list) <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">nchoose_split l</code> does the same as <a href="Lwt.html#VALnchoose"><code class="code"><span class="constructor">Lwt</span>.nchoose</code></a> but also retrurns
      the list of threads that have not yet terminated.<br>
</div>
<pre><span id="VALjoin"><span class="keyword">val</span> join</span> : <code class="type">unit <a href="Lwt.html#TYPEt">t</a> list -> unit <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">join l</code> waits for all threads in <code class="code">l</code> to terminate. If one of
      the threads fails, then <code class="code">join l</code> will fails with the same
      exception as the first one to terminate.
<p>

      Note: <a href="Lwt.html#VALjoin"><code class="code"><span class="constructor">Lwt</span>.join</code></a> leaves the local values of the current thread
      unchanged.<br>
</div>
<pre><span id="VAL(<?>)"><span class="keyword">val</span> (&lt;?&gt;)</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> 'a <a href="Lwt.html#TYPEt">t</a> -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">t &lt;?&gt; t'</code> is the same as <code class="code">choose [t; t']</code><br>
</div>
<pre><span id="VAL(<&>)"><span class="keyword">val</span> (&lt;&amp;&gt;)</span> : <code class="type">unit <a href="Lwt.html#TYPEt">t</a> -> unit <a href="Lwt.html#TYPEt">t</a> -> unit <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">t &lt;&amp;&gt; t'</code> is the same as <code class="code">join [t; t']</code><br>
</div>
<pre><span id="VALignore_result"><span class="keyword">val</span> ignore_result</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> unit</code></pre><div class="info">
<code class="code">ignore_result t</code> start the thread <code class="code">t</code> and ignores its result
      value if the thread terminates sucessfully.  However, if the
      thread <code class="code">t</code> fails, the exception is raised instead of being
      ignored.
<p>

      You should use this function if you want to start a thread and
      don't care what its return value is, nor when it terminates (for
      instance, because it is looping).  Note that if the thread <code class="code">t</code>
      yields and later fails, the exception will not be raised at this
      point in the program.<br>
</div>
<br>
<span id="6_Sleepingandresuming"><h6>Sleeping and resuming</h6></span><br>
<pre><span id="TYPEu"><span class="keyword">type</span> <code class="type">'a</code> u</span> </pre>
<div class="info">
The type of thread wakeners.<br>
</div>

<pre><span id="VALwait"><span class="keyword">val</span> wait</span> : <code class="type">unit -> 'a <a href="Lwt.html#TYPEt">t</a> * 'a <a href="Lwt.html#TYPEu">u</a></code></pre><div class="info">
<code class="code">wait ()</code> is a pair of a thread which sleeps forever (unless it
      is resumed by one of the functions <code class="code">wakeup</code>, <code class="code">wakeup_exn</code> below)
      and the corresponding wakener.  This thread does not block the
      execution of the remainder of the program (except of course, if
      another thread tries to wait for its termination).<br>
</div>
<pre><span id="VALwakeup"><span class="keyword">val</span> wakeup</span> : <code class="type">'a <a href="Lwt.html#TYPEu">u</a> -> 'a -> unit</code></pre><div class="info">
<code class="code">wakeup t e</code> makes the sleeping thread <code class="code">t</code> terminate and return
      the value of the expression <code class="code">e</code>.<br>
</div>
<pre><span id="VALwakeup_exn"><span class="keyword">val</span> wakeup_exn</span> : <code class="type">'a <a href="Lwt.html#TYPEu">u</a> -> exn -> unit</code></pre><div class="info">
<code class="code">wakeup_exn t e</code> makes the sleeping thread <code class="code">t</code> fail with the
      exception <code class="code">e</code>.<br>
</div>
<pre><span id="VALwakeup_later"><span class="keyword">val</span> wakeup_later</span> : <code class="type">'a <a href="Lwt.html#TYPEu">u</a> -> 'a -> unit</code></pre><div class="info">
Same as <a href="Lwt.html#VALwakeup"><code class="code"><span class="constructor">Lwt</span>.wakeup</code></a> but it is not guaranteed that the thread will
      be wakeup immediately.<br>
</div>
<pre><span id="VALwakeup_later_exn"><span class="keyword">val</span> wakeup_later_exn</span> : <code class="type">'a <a href="Lwt.html#TYPEu">u</a> -> exn -> unit</code></pre><div class="info">
Same as <a href="Lwt.html#VALwakeup_exn"><code class="code"><span class="constructor">Lwt</span>.wakeup_exn</code></a> but it is not guaranteed that the thread
      will be wakeup immediately.<br>
</div>
<pre><span id="VALwaiter_of_wakener"><span class="keyword">val</span> waiter_of_wakener</span> : <code class="type">'a <a href="Lwt.html#TYPEu">u</a> -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
Returns the thread associated to a wakener.<br>
</div>
<br>
<span id="6_Threadsstate"><h6>Threads state</h6></span><br>
<br><code><span id="TYPEstate"><span class="keyword">type</span> <code class="type">'a</code> state</span> = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">Return</span> <span class="keyword">of</span> <code class="type">'a</code></code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >The thread which has successfully terminated</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">Fail</span> <span class="keyword">of</span> <code class="type">exn</code></code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >The thread raised an exception</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">Sleep</span></code></td>
<td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >The thread is sleeping</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td>
</tr></table>

<div class="info">
State of a thread<br>
</div>

<pre><span id="VALstate"><span class="keyword">val</span> state</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> 'a <a href="Lwt.html#TYPEstate">state</a></code></pre><div class="info">
<code class="code">state t</code> returns the state of a thread<br>
</div>
<br>
<span id="6_Cancelablethreads"><h6>Cancelable threads</h6></span><br>
<br>
Cancelable threads are the same as regular threads except that
    they can be canceled.<br>
<pre><span id="EXCEPTIONCanceled"><span class="keyword">exception</span> Canceled</span></pre>
<div class="info">
Canceled threads fails with this exception<br>
</div>
<pre><span id="VALtask"><span class="keyword">val</span> task</span> : <code class="type">unit -> 'a <a href="Lwt.html#TYPEt">t</a> * 'a <a href="Lwt.html#TYPEu">u</a></code></pre><div class="info">
<code class="code">task ()</code> is the same as <code class="code">wait ()</code> except that threads created
      with <code class="code">task</code> can be canceled.<br>
</div>
<pre><span id="VALon_cancel"><span class="keyword">val</span> on_cancel</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> (unit -> unit) -> unit</code></pre><div class="info">
<code class="code">on_cancel t f</code> executes <code class="code">f</code> when <code class="code">t</code> is canceled. This is the
      same as catching <code class="code"><span class="constructor">Canceled</span></code>.<br>
</div>
<pre><span id="VALcancel"><span class="keyword">val</span> cancel</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> unit</code></pre><div class="info">
<code class="code">cancel t</code> cancels the threads <code class="code">t</code>. This means that the deepest
      sleeping thread created with <code class="code">task</code> and connected to <code class="code">t</code> is
      woken up with the exception <a href="Lwt.html#EXCEPTIONCanceled"><code class="code"><span class="constructor">Lwt</span>.<span class="constructor">Canceled</span></code></a>.
<p>

      For example, in the following code:
<p>

      <pre></pre><code class="code">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;waiter,&nbsp;wakener&nbsp;=&nbsp;task&nbsp;()&nbsp;<span class="keyword">in</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cancel&nbsp;(waiter&nbsp;&gt;&gt;&nbsp;printl&nbsp;<span class="string">"plop"</span>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><pre></pre>
<p>

      <code class="code">waiter</code> will be woken up with <a href="Lwt.html#EXCEPTIONCanceled"><code class="code"><span class="constructor">Lwt</span>.<span class="constructor">Canceled</span></code></a>.<br>
</div>
<pre><span id="VALpick"><span class="keyword">val</span> pick</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> list -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">pick l</code> is the same as <a href="Lwt.html#VALchoose"><code class="code"><span class="constructor">Lwt</span>.choose</code></a>, except that it cancels all
      sleeping threads when one terminates.
<p>

      Note: <a href="Lwt.html#VALpick"><code class="code"><span class="constructor">Lwt</span>.pick</code></a> leaves the local values of the current thread
      unchanged.<br>
</div>
<pre><span id="VALnpick"><span class="keyword">val</span> npick</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> list -> 'a list <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">npick l</code> is the same as <a href="Lwt.html#VALnchoose"><code class="code"><span class="constructor">Lwt</span>.nchoose</code></a>, except that it cancels all
      sleeping threads when one terminates.
<p>

      Note: <a href="Lwt.html#VALnpick"><code class="code"><span class="constructor">Lwt</span>.npick</code></a> leaves the local values of the current thread
      unchanged.<br>
</div>
<pre><span id="VALprotected"><span class="keyword">val</span> protected</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> 'a <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">protected thread</code> creates a new cancelable thread which behave
      as <code class="code">thread</code> except that cancelling it does not cancel
      <code class="code">thread</code>.<br>
</div>
<br>
<span id="6_Pause"><h6>Pause</h6></span><br>
<pre><span id="VALpause"><span class="keyword">val</span> pause</span> : <code class="type">unit -> unit <a href="Lwt.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">pause ()</code> is a sleeping thread which is wake up on the next
      call to <a href="Lwt.html#VALwakeup_paused"><code class="code"><span class="constructor">Lwt</span>.wakeup_paused</code></a>. A thread created with <code class="code">pause</code> can be
      canceled.<br>
</div>
<pre><span id="VALwakeup_paused"><span class="keyword">val</span> wakeup_paused</span> : <code class="type">unit -> unit</code></pre><div class="info">
<code class="code">wakeup_paused ()</code> wakes up all threads which suspended
      themselves with <a href="Lwt.html#VALpause"><code class="code"><span class="constructor">Lwt</span>.pause</code></a>.
<p>

      This function is called by the scheduler, before entering the
      main loop. You usually do not have to call it directly, except
      if you are writing a custom scheduler.
<p>

      Note that if a paused thread resume and pause again, it will not
      be wakeup at this point.<br>
</div>
<pre><span id="VALpaused_count"><span class="keyword">val</span> paused_count</span> : <code class="type">unit -> int</code></pre><div class="info">
<code class="code">paused_count ()</code> returns the number of thread currently
      paused.<br>
</div>
<pre><span id="VALregister_pause_notifier"><span class="keyword">val</span> register_pause_notifier</span> : <code class="type">(int -> unit) -> unit</code></pre><div class="info">
<code class="code">register_pause_notifier f</code> register a function <code class="code">f</code> that will be
      called each time pause is called. The parameter passed to <code class="code">f</code> is
      the new number of threads paused. It is usefull to be able to
      call <a href="Lwt.html#VALwakeup_paused"><code class="code"><span class="constructor">Lwt</span>.wakeup_paused</code></a> when there is no scheduler<br>
</div>
<br>
<span id="6_Misc"><h6>Misc</h6></span><br>
<pre><span id="VALon_success"><span class="keyword">val</span> on_success</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> ('a -> unit) -> unit</code></pre><div class="info">
<code class="code">on_success t f</code> executes <code class="code">f</code> when <code class="code">t</code> terminates without
      failing. This is the same as:
<p>

      <pre></pre><code class="code">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore_result&nbsp;(bind&nbsp;t&nbsp;(<span class="keyword">fun</span>&nbsp;x&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;f&nbsp;x;&nbsp;return&nbsp;()))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><pre></pre>
<p>

      but a bit more efficient.<br>
</div>
<pre><span id="VALon_failure"><span class="keyword">val</span> on_failure</span> : <code class="type">'a <a href="Lwt.html#TYPEt">t</a> -> (exn -> unit) -> unit</code></pre><div class="info">
<code class="code">on_failure t f</code> executes <code class="code">f</code> when <code class="code">t</code> terminates and
      fails. This is the same as:
<p>

      <pre></pre><code class="code">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore_result&nbsp;(catch&nbsp;t&nbsp;(<span class="keyword">fun</span>&nbsp;e&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;f&nbsp;e;&nbsp;return&nbsp;()))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><pre></pre>
<p>

      but a bit more efficient.<br>
</div>
</body></html>