ribesg
@Test fun test() { val threadPool = newFixedThreadPoolContext(8, "TestDispatcher") val scope = CoroutineScope(threadPool) val atomic = atomic(0L) repeat(100_000) { scope.launch { atomic.incrementAndGet() } } assertEquals(100_000, atomic.value) }
jw
@Test fun test() = runBlocking { val threadPool = newFixedThreadPoolContext(8, "TestDispatcher") val scope = CoroutineScope(threadPool) val atomic = atomic(0L) val jobs = (1..100_000).map { scope.launch { atomic.incrementAndGet() } } jobs.joinAll() assertEquals(100_000, atomic.value) }
A modern programming language that makes developers happier.