Skip to content

Commit

Permalink
Fix asSuspendable.par.map method when the collection is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Jun 1, 2012
1 parent 7c8aca6 commit 91e9369
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,25 @@ object CollectionConverters {
})

final def map[B: Manifest](f: A => B @suspendable): Array[B] @suspendable =
shift(
new AtomicInteger(underline.size) with ((Array[B] => Unit) => Unit) {
override final def apply(continue: Array[B] => Unit) {
val results = new Array[B](super.get)
for ((element, i) <- underline.view zipWithIndex) {
reset {
val result = f(element)
results(i) = result
if (super.decrementAndGet() == 0) {
continue(results)
if (underline.isEmpty) {
Array.empty[B]
} else {
shift(
new AtomicInteger(underline.size) with ((Array[B] => Unit) => Unit) {
override final def apply(continue: Array[B] => Unit) {
val results = new Array[B](super.get)
for ((element, i) <- underline.view zipWithIndex) {
reset {
val result = f(element)
results(i) = result
if (super.decrementAndGet() == 0) {
continue(results)
}
}
}
}
}
})
})
}
}

final class AsParallelSuspendableIterable[+A](
Expand Down

0 comments on commit 91e9369

Please sign in to comment.