Skip to content

Commit 67c88a7

Browse files
committed
unbuffered channels now by default (as in go)
1 parent 9956ae3 commit 67c88a7

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

src/main/scala/gopher/GopherAPI.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class GopherAPI(as: ActorSystem, es: ExecutionContext)
4141
* channel.awrite(1 to 100)
4242
*}}}
4343
*/
44-
def makeChannel[A](capacity: Int = 1) =
44+
def makeChannel[A](capacity: Int = 0) =
4545
{
4646
require(capacity >= 0)
4747
val nextId = newChannelId

src/main/scala/gopher/channels/Channel.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import scala.reflect.api._
1414
abstract class Channel[A](override val api: GopherAPI) extends InputOutput[A]
1515
{
1616

17+
1718
def close(): Unit
1819

1920
}

src/main/scala/gopher/channels/DuppedInput.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class DuppedInput[A](origin:Input[A])
1515

1616
def pair = (sink1, sink2)
1717

18-
val sink1 = api.makeChannel[A]()
19-
val sink2 = api.makeChannel[A]()
18+
val sink1 = api.makeChannel[A](1)
19+
val sink2 = api.makeChannel[A](1)
2020

2121
// can't use macroses, so unroll by hands.
2222
private val selector = api.select.forever;

src/test/scala/gopher/channels/DuppedChannelsSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DuppedChannelsSuite extends FunSuite with AsyncAssertions {
4949
}
5050

5151
test("on closing of main stream dupped outputs also closed.") {
52-
val ch = gopherApi.makeChannel[Int]()
52+
val ch = gopherApi.makeChannel[Int](1)
5353
val (in1, in2) = ch.dup
5454
val f1 = go {
5555
ch.write(1)

src/test/scala/gopher/channels/IOTimeoutsSuite.scala

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class IOTimeoutsSuite extends FunSuite with AsyncAssertions {
4747

4848
test("on input close it's timeout channel also must close") {
4949
val w = new Waiter()
50-
val ch = gopherApi.makeChannel[String]()
50+
val ch = gopherApi.makeChannel[String](1)
5151
Await.ready(ch.awrite("qqq"), 1 second)
5252
val (chReady, chTimeout) = ch.withInputTimeouts(300 milliseconds)
5353
ch.close()
@@ -73,10 +73,25 @@ class IOTimeoutsSuite extends FunSuite with AsyncAssertions {
7373
}
7474

7575

76-
test("messsaged from timeouts must be appear during attempt to write to filled channel") {
76+
test("messsaged from timeouts must be appear during attempt to write to filled unbuffered channel") {
7777
val ch = gopherApi.makeChannel[Int]()
7878
val (chReady, chTimeout) = ch.withOutputTimeouts(150 milliseconds)
7979
@volatile var count = 1
80+
val f = gopherApi.select.forever {
81+
case x: chReady.write if (x==count) =>
82+
{};
83+
count += 1 // will newer called, since we have no reader
84+
case t: chTimeout.read =>
85+
implicitly[FlowTermination[Unit]].doExit(count)
86+
}
87+
Await.ready(f, 1 second)
88+
assert(count==1)
89+
}
90+
91+
test("messsaged from timeouts must be appear during attempt to write to filled buffered channel") {
92+
val ch = gopherApi.makeChannel[Int](1)
93+
val (chReady, chTimeout) = ch.withOutputTimeouts(150 milliseconds)
94+
@volatile var count = 1
8095
val f = gopherApi.select.forever {
8196
case x: chReady.write if (x==count) =>
8297
{};
@@ -89,7 +104,7 @@ class IOTimeoutsSuite extends FunSuite with AsyncAssertions {
89104
}
90105

91106
test("when we have where to write -- no timeouts") {
92-
val ch = gopherApi.makeChannel[Int]()
107+
val ch = gopherApi.makeChannel[Int](1)
93108
val (chReady, chTimeout) = ch.withOutputTimeouts(300 milliseconds)
94109
val f = gopherApi.select.once {
95110
case x: chReady.write if (x==1) => 1
@@ -100,7 +115,7 @@ class IOTimeoutsSuite extends FunSuite with AsyncAssertions {
100115
}
101116

102117
test("on output close it's timeout channel also must close") {
103-
val ch = gopherApi.makeChannel[Int]()
118+
val ch = gopherApi.makeChannel[Int](1)
104119
val (chReady, chTimeout) = ch.withOutputTimeouts(300 milliseconds)
105120
val w = new Waiter()
106121
val f1 = chReady.awrite(1)

0 commit comments

Comments
 (0)