11package com.baeldung.kotlin
22
3- import kotlinx.coroutines.experimental. *
3+ import kotlinx.coroutines.*
44import org.junit.Test
55import java.util.concurrent.atomic.AtomicInteger
6- import kotlin.coroutines.experimental.buildSequence
76import kotlin.system.measureTimeMillis
87import kotlin.test.assertEquals
98import kotlin.test.assertTrue
@@ -14,7 +13,7 @@ class CoroutinesTest {
1413 @Test
1514 fun givenBuildSequence_whenTakeNElements_thenShouldReturnItInALazyWay () {
1615 // given
17- val fibonacciSeq = buildSequence {
16+ val fibonacciSeq = sequence {
1817 var a = 0
1918 var b = 1
2019
@@ -39,7 +38,7 @@ class CoroutinesTest {
3938 @Test
4039 fun givenLazySeq_whenTakeNElements_thenShouldReturnAllElements () {
4140 // given
42- val lazySeq = buildSequence {
41+ val lazySeq = sequence {
4342 print (" START " )
4443 for (i in 1 .. 5 ) {
4544 yield (i)
@@ -60,8 +59,8 @@ class CoroutinesTest {
6059 val res = mutableListOf<String >()
6160
6261 // when
63- runBlocking< Unit > {
64- val promise = launch(CommonPool ) { expensiveComputation(res) }
62+ runBlocking {
63+ val promise = launch(Dispatchers . Default ) { expensiveComputation(res) }
6564 res.add(" Hello," )
6665 promise.join()
6766 }
@@ -85,7 +84,7 @@ class CoroutinesTest {
8584
8685 // when
8786 val jobs = List (numberOfCoroutines) {
88- launch(CommonPool ) {
87+ launch(Dispatchers . Default ) {
8988 delay(1L )
9089 counter.incrementAndGet()
9190 }
@@ -101,7 +100,7 @@ class CoroutinesTest {
101100 fun givenCancellableJob_whenRequestForCancel_thenShouldQuit () {
102101 runBlocking<Unit > {
103102 // given
104- val job = launch(CommonPool ) {
103+ val job = launch(Dispatchers . Default ) {
105104 while (isActive) {
106105 // println("is working")
107106 }
@@ -135,8 +134,8 @@ class CoroutinesTest {
135134 val delay = 1000L
136135 val time = measureTimeMillis {
137136 // given
138- val one = async(CommonPool ) { someExpensiveComputation(delay) }
139- val two = async(CommonPool ) { someExpensiveComputation(delay) }
137+ val one = async(Dispatchers . Default ) { someExpensiveComputation(delay) }
138+ val two = async(Dispatchers . Default ) { someExpensiveComputation(delay) }
140139
141140 // when
142141 runBlocking {
@@ -156,8 +155,8 @@ class CoroutinesTest {
156155 val delay = 1000L
157156 val time = measureTimeMillis {
158157 // given
159- val one = async(CommonPool , CoroutineStart .LAZY ) { someExpensiveComputation(delay) }
160- val two = async(CommonPool , CoroutineStart .LAZY ) { someExpensiveComputation(delay) }
158+ val one = async(Dispatchers . Default , CoroutineStart .LAZY ) { someExpensiveComputation(delay) }
159+ val two = async(Dispatchers . Default , CoroutineStart .LAZY ) { someExpensiveComputation(delay) }
161160
162161 // when
163162 runBlocking {
0 commit comments