-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from rokostik/concurrency-improvements
Improve concurrent functionality
- Loading branch information
Showing
9 changed files
with
267 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/examples-wip/goroutines_B.rye → .../examples-wip/goroutines/goroutines_B.rye
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
jobs: new-channel 5 | ||
done: new-channel 0 | ||
|
||
go fn { } { | ||
print "waiting to process jobs" | ||
forever { | ||
j: read jobs |fix { | ||
print "recieved all jobs" | ||
send done 1 | ||
return | ||
} | ||
|
||
print\ssv vals { "received job" j } | ||
sleep 1000 | ||
} | ||
} | ||
|
||
loop 3 { :i | ||
send jobs i | ||
print\ssv vals { "sent job" i } | ||
} | ||
close jobs | ||
|
||
print "waiting for jobs to finish" | ||
read done | ||
print "finished" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
c1: new-channel 0 | ||
c2: new-channel 0 | ||
|
||
go fn { } { | ||
sleep 1000 | ||
send c1 "one" | ||
} | ||
go fn { } { | ||
sleep 2000 | ||
send c2 "two" | ||
} | ||
|
||
loop 2 { | ||
select { | ||
c1 fn { msg } { | ||
print\ssv vals { "received from c1:" msg } | ||
} | ||
c2 fn { msg } { | ||
print\ssv vals { "received from c2:" msg } | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/examples-wip/goroutines/goroutines_select_default.rye
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
c: new-channel 0 | ||
|
||
go fn { } { | ||
sleep 1000 | ||
send c "hello" | ||
} | ||
|
||
loop 5 { | ||
select { | ||
c fn { msg } { | ||
print msg | ||
} | ||
fn { } { | ||
print "default" | ||
sleep 500 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
wg: new-waitgroup | ||
|
||
work: fn { id } { | ||
print\ssv vals { "worker" id "starting" } | ||
sleep 1000 | ||
print\ssv vals { "worker" id "done" } | ||
wg .done | ||
} | ||
|
||
loop 5 { :i | ||
wg .add 1 | ||
go-with i ?work | ||
} | ||
|
||
print "waiting for workers to finish" | ||
wg .wait | ||
print "finished" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters