Changeset 33959 in project


Ignore:
Timestamp:
04/10/17 23:58:38 (5 months ago)
Author:
kristianlm
Message:

gochan update from its readme

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/gochan

    r33935 r33959  
    55synchronization.
    66
    7 chicken-gochan has no egg dependencies.
     7
     8=== Dependencies
     9* [[wiki.call-cc.org/eggref/4/matchable|matchable]]
    810
    911
     
    1214
    1315* receive and send switch ({{gochan-select}})
     16* buffered channels
    1417* timeouts as ordinary receive on a channel
    1518* closable channels
    1619* load-balancing when multiple channels have data ready
     20
     21
     22===== TODO
     23* Add an {{else}} clause ([[http://golang.org/|Go]]'s {{default}}) to {{gochan-select}}
    1724
    1825
     
    2229
    2330* channels don't have any type information
    24 * sending to a channel that gets closed does not panic, it returns
    25   (all sender) immediately with the {{ok}} flag set to {{#f}}.
     31* sending to a channel that gets closed does not panic, it unblocks
     32  all senders immediately with the {{ok}} flag set to {{#f}}.
    2633* closing an already closed channel has no effect, and is not an error
    2734  ({{gochan-close}} is idempotent).
     
    4249to be ready will be executed.
    4350
    44 Receive clauses, {{((chan <- msg [ok]) body ...)}}, execute {{body}} with
     51Receive clauses, {{((chan -> msg [ok]) body ...)}}, execute {{body}} with
    4552{{msg}} bound to the message object, and optionally {{ok}} bound to a flag
    4653indicating success ({{#t}}) or not ({{#f}} if channel was closed).
    4754
    48 Send clauses, {{((chan -> msg [ok]) body ...)}}, execute {{body}} after
     55Send clauses, {{((chan <- msg [ok]) body ...)}}, execute {{body}} after
    4956{{msg}} has been sent to a receiver, successfully buffered onto the
    5057channel, or if channel was closed. Again, the optional variable name
     
    6067(gochan-select
    6168 ((chan1 -> msg ok) (if ok
    62                         (print "chan3 says " msg)
    63                         (print "chan3 was closed!")))
     69                        (print "chan1 says " msg)
     70                        (print "chan1 was closed!")))
    6471 ((chan2 <- 123) (print "somebody will get/has gotten 123 on chan2") ))
    6572</enscript>
     
    8895{{duration/ms}} milliseconds of its creation. The message is the
    8996{{(current-milliseconds)}} value at the time of the timeout (not when
    90 the message was received).
     97the message was received). Receiving more than once on an
     98{{gochan-after}} channel will block indefinitely the second time.
     99
     100<enscript highlight="scheme">   
     101(gochan-select
     102 ((chan1 -> msg)                (print "chan1 says " msg))
     103 (((gochan-after 1000) -> when) (print "chan1 took too long")))
     104</enscript>
     105
     106You cannot send to or close a timer channel. These are special records
     107that contain information about when the next timer will
     108trigger. Creating timers is a relatively cheap operation, and
     109unlike [[https://golang.org/pkg/time/#After|golang.time.After]], may be
     110garbage-collected before the timer triggers.
    91111
    92112<procedure> (gochan-tick duration/ms)</procedure>
     
    96116value at the time of the tick (not when it was received).
    97117
     118See [[tests/worker-pool.scm|{{tests/worker-pool.scm}}]] for
     119an example of its use.
     120
    98121<procedure> (go body ...)</procedure>
    99122
     
    102125
    103126
    104 === TODO
    105 * Add an {{else}} clause ([[http://golang.org/|Go]]'s {{default}}) to {{gochan-select}}
    106 
    107 
    108127=== Samples
    109128See {{./tests/worker-pool.scm}} for a port of
Note: See TracChangeset for help on using the changeset viewer.