1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.example.tracing.demo.experiments 17 18 import com.android.app.tracing.coroutines.launchTraced as launch 19 import com.example.tracing.demo.Default 20 import com.example.tracing.demo.FixedThreadA 21 import com.example.tracing.demo.FixedThreadB 22 import com.example.tracing.demo.FixedThreadC 23 import com.example.tracing.demo.IO 24 import com.example.tracing.demo.Unconfined 25 import javax.inject.Inject 26 import javax.inject.Singleton 27 import kotlinx.coroutines.CoroutineDispatcher 28 import kotlinx.coroutines.coroutineScope 29 30 @Singleton 31 class LaunchSequentially 32 @Inject 33 constructor( 34 @FixedThreadA private var dispatcherA: CoroutineDispatcher, 35 @FixedThreadB private var dispatcherB: CoroutineDispatcher, 36 @FixedThreadC private val dispatcherC: CoroutineDispatcher, 37 @Default private var defaultContext: CoroutineDispatcher, 38 @IO private var ioContext: CoroutineDispatcher, 39 @Unconfined private var unconfinedContext: CoroutineDispatcher, 40 ) : Experiment { 41 override val description: String = "launch{};launch{};launch{};launch{}" 42 <lambda>null43 override suspend fun start(): Unit = coroutineScope { 44 launch("launch(threadA)", dispatcherA) { forceSuspend("A", 250) } 45 launch("launch(threadB)", dispatcherB) { forceSuspend("B", 250) } 46 launch("launch(threadC)", dispatcherC) { forceSuspend("C", 250) } 47 launch("launch(Dispatchers.Default)", defaultContext) { forceSuspend("D", 250) } 48 launch("launch(EmptyCoroutineContext)") { forceSuspend("E", 250) } 49 launch("launch(Dispatchers.IO)", ioContext) { forceSuspend("F", 250) } 50 launch("launch(Dispatchers.Unconfined)", unconfinedContext) { forceSuspend("G", 250) } 51 } 52 } 53