@@ -16,7 +16,7 @@ function cond(...clauses) {
1616
1717function run_list_generators ( generator , generators ) {
1818 if ( generators . length === 0 ) {
19- return generator . map ( ( x ) => {
19+ return generator . map ( x => {
2020 if ( Array . isArray ( x ) ) {
2121 return x ;
2222 }
@@ -42,14 +42,23 @@ function _for(expression, generators, collectable_protocol, into = []) {
4242
4343 for ( const value of generatedValues ) {
4444 if ( expression . guard . apply ( this , value ) ) {
45- result = fun ( result , new Core . Tuple ( Symbol . for ( 'cont' ) , expression . fn . apply ( this , value ) ) ) ;
45+ result = fun (
46+ result ,
47+ new Core . Tuple ( Symbol . for ( 'cont' ) , expression . fn . apply ( this , value ) )
48+ ) ;
4649 }
4750 }
4851
4952 return fun ( result , Symbol . for ( 'done' ) ) ;
5053}
5154
52- function _try ( do_fun , rescue_function , catch_fun , else_function , after_function ) {
55+ function _try (
56+ do_fun ,
57+ rescue_function ,
58+ catch_fun ,
59+ else_function ,
60+ after_function
61+ ) {
5362 let result = null ;
5463
5564 try {
@@ -132,8 +141,29 @@ function _with(...args) {
132141 return successFunction ( ...argsToPass ) ;
133142}
134143
135- function receive ( ) {
144+ function receive ( clauses , timeout = 0 , timeoutFn = ( ) => true ) {
136145 console . warn ( 'Receive not supported' ) ;
146+
147+ const messages = [ ] ; //this.mailbox.get();
148+ const NOMATCH = Symbol ( ) ;
149+
150+ for ( let i = 0 ; i < messages . length ; i ++ ) {
151+ for ( const clause of clauses ) {
152+ const value = Patterns . match_or_default (
153+ clause . pattern ,
154+ messages [ i ] ,
155+ clause . guard ,
156+ NOMATCH
157+ ) ;
158+
159+ if ( value !== NOMATCH ) {
160+ this . mailbox . removeAt ( i ) ;
161+ return clause . fn . apply ( null , value ) ;
162+ }
163+ }
164+ }
165+
166+ return null ;
137167}
138168
139169export default {
@@ -142,5 +172,5 @@ export default {
142172 _for,
143173 _try,
144174 _with,
145- receive,
175+ receive
146176} ;
0 commit comments