Skip to content

Commit 13d2804

Browse files
committed
slightly corrected examples.
1 parent db164a5 commit 13d2804

File tree

3 files changed

+20
-41
lines changed

3 files changed

+20
-41
lines changed

src/main/scala/gopher/goasync/GoAsync.scala

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,36 +134,19 @@ object GoAsync
134134
if (found) {
135135
// this can be implicit parameters of inline apply.
136136
// whe can distinguish first from second by looking at f1 shape.
137-
// for now will assume
138-
System.err.println(s"inline-await + implicit, a2=${a2}")
139-
System.err.println(s"inline-await ,tree=${tree}")
140-
System.err.println(s"inline-await ,tree.tpe=${tree.tpe}")
141-
val isImplicit = f1 match {
142-
case TypeApply(Select(x,m),w) =>
143-
System.err.println(s"typed select, x=$x, m=$m, w=$w")
144-
System.err.println(s"x.tpe=${x.tpe}")
145-
System.err.println(s"x.symbol=${x.symbol}")
146-
System.err.println(s"tree.symbol=${tree.symbol}")
147-
if (! (x.tpe eq null) ) {
148-
val sym = x.tpe.member(m)
149-
System.err.println("sym=$sym")
150-
} else {
151-
true
152-
}
153-
case q"$x.$m[$w]" =>
154-
System.err.println(s"typed select, x=$x, m=$m, w=$w")
155-
case q"$x.$m" =>
156-
System.err.println(s"select, x=$x, m=$m")
157-
true
158-
case q"($x.$m)[$w]" =>
159-
System.err.println(s"typed select-1, x=$x, m=$m, w=$w")
160-
true
161-
case _ =>
162-
System.err.println(s"other: ${f1}")
163-
System.err.println(s"raw: ${showRaw(f1)}")
164-
true
137+
val isTwoParams = if (!(tree.symbol eq null)) {
138+
if (tree.symbol.isMethod) {
139+
tree.symbol.asMethod.paramLists.size == 2
140+
} else if (tree.symbol eq NoSymbol) {
141+
// untyped, hope for the best
142+
true
143+
} else false
144+
} else true
145+
if (isTwoParams) {
146+
transformInlineHofCall1(c)(f1,a,b,a2)
147+
} else {
148+
super.transform(tree)
165149
}
166-
transformInlineHofCall1(c)(f1,a,b,a2)
167150
}else{
168151
super.transform(tree)
169152
}

src/test/scala/example/BroadcasterSuite.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ class BroadcaseSuite extends FunSuite
107107
var finish = false;
108108
while(!finish) {
109109
val x = await(r.aread)
110-
// can't use foreach inside 'go' block.
111-
if (!x.isEmpty) {
112-
out.write(x.get)
113-
} else {
114-
finish = true
110+
x match {
111+
case Some(m) => out.write(m)
112+
case None => finish = true
115113
}
116114
}
117115
();

src/test/scala/example/FibonaccySuite.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ object Fibonaccy {
3636
val c = gopherApi.makeChannel[Long](1);
3737
val quit = gopherApi.makeChannel[Int](1);
3838
val r = go {
39-
// for loop in go with async insied yet not supported
40-
var i = 1
41-
while(i <= n) {
42-
val x: Long = (c ?)
43-
//Console.println(s"received: ${i}, ${x}")
44-
acceptor(x)
45-
i += 1
39+
// for loop in go with async inside
40+
for( i<- 1 to n) {
41+
val x: Long = (c ?)
42+
//Console.println(s"received: ${i}, ${x}")
43+
acceptor(x)
4644
}
4745
quit <~ 0
4846
}

0 commit comments

Comments
 (0)