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 javax.inject.Inject 25 import javax.inject.Singleton 26 import kotlinx.coroutines.CoroutineDispatcher 27 import kotlinx.coroutines.coroutineScope 28 29 @Singleton 30 class LaunchNested 31 @Inject 32 constructor( 33 @FixedThreadA private var dispatcherA: CoroutineDispatcher, 34 @FixedThreadB private var dispatcherB: CoroutineDispatcher, 35 @FixedThreadC private val dispatcherC: CoroutineDispatcher, 36 @Default private var defaultContext: CoroutineDispatcher, 37 @IO private var ioContext: CoroutineDispatcher, 38 ) : Experiment { 39 override val description: String = "launch{launch{launch{launch{}}}}" 40 <lambda>null41 override suspend fun start(): Unit = coroutineScope { 42 launch("launch(threadA)", dispatcherA) { 43 forceSuspend("A", 250) 44 launch("launch(threadB)", dispatcherB) { 45 forceSuspend("B", 250) 46 launch("launch(threadC)", dispatcherC) { 47 forceSuspend("C", 250) 48 launch("launch(Dispatchers.Default)", defaultContext) { 49 forceSuspend("D", 250) 50 launch("launch(Dispatchers.IO)", ioContext) { forceSuspend("E", 250) } 51 } 52 } 53 } 54 } 55 } 56 } 57