@@ -36,17 +36,21 @@ function run_list_generators(generator, generators) {
3636}
3737
3838function _for ( expression , generators , collectable_protocol , into = [ ] ) {
39- let [ result , fun ] = collectable_protocol . into ( into ) ;
39+ const [ result , fun ] = collectable_protocol . into ( into ) ;
40+ let accumulatingResult = result ;
4041
4142 const generatedValues = run_list_generators ( generators . pop ( ) ( ) , generators ) ;
4243
4344 for ( const value of generatedValues ) {
4445 if ( expression . guard . apply ( this , value ) ) {
45- result = fun ( result , new Core . Tuple ( Symbol . for ( 'cont' ) , expression . fn . apply ( this , value ) ) ) ;
46+ accumulatingResult = fun (
47+ accumulatingResult ,
48+ new Core . Tuple ( Symbol . for ( 'cont' ) , expression . fn . apply ( this , value ) ) ,
49+ ) ;
4650 }
4751 }
4852
49- return fun ( result , Symbol . for ( 'done' ) ) ;
53+ return fun ( accumulatingResult , Symbol . for ( 'done' ) ) ;
5054}
5155
5256function _try ( do_fun , rescue_function , catch_fun , else_function , after_function ) {
@@ -132,8 +136,29 @@ function _with(...args) {
132136 return successFunction ( ...argsToPass ) ;
133137}
134138
135- function receive ( ) {
139+ function receive ( clauses , timeout = 0 , timeoutFn = ( ) => true ) {
136140 console . warn ( 'Receive not supported' ) ;
141+
142+ const messages = [ ] ; // this.mailbox.get();
143+ const NOMATCH = Symbol ( 'NOMATCH' ) ;
144+
145+ for ( let i = 0 ; i < messages . length ; i ++ ) {
146+ for ( const clause of clauses ) {
147+ const value = Core . Patterns . match_or_default (
148+ clause . pattern ,
149+ messages [ i ] ,
150+ clause . guard ,
151+ NOMATCH ,
152+ ) ;
153+
154+ if ( value !== NOMATCH ) {
155+ this . mailbox . removeAt ( i ) ;
156+ return clause . fn . apply ( null , value ) ;
157+ }
158+ }
159+ }
160+
161+ return null ;
137162}
138163
139164export default {
0 commit comments