Skip to content

Parallel execution? #21

@atonamy

Description

@atonamy

When I try to execute several tasks in parallel my code looks ugly.

async {
           await {
               async {
                   await {
                       async {
                           await {
                               val it = System.currentTimeMillis()
                               while (System.currentTimeMillis() - it < 5000);
                               Log.w("Executing coroutine", "Task1")
                           }
                       }
                       val it = System.currentTimeMillis()
                       while (System.currentTimeMillis() - it < 5000);
                       Log.w("Executing coroutine", "Task2")
                   }
               }
               val it = System.currentTimeMillis()
               while(System.currentTimeMillis() - it < 5000 );
               Log.w("Executing coroutine", "Task3")
           }

           Log.w("Executing coroutine", "All tasks completed")
       }

Is any way to make parallel execution looks more elegant?
Something like this

 async {
            awaitParallel  {
                val it = System.currentTimeMillis()
                while (System.currentTimeMillis() - it < 5000);
                Log.w("Executing coroutine", "Task1")
            }
            awaitParallel  {
                val it = System.currentTimeMillis()
                while (System.currentTimeMillis() - it < 5000);
                Log.w("Executing coroutine", "Task2")
            }
            awaitParallel  {
                val it = System.currentTimeMillis()
                while (System.currentTimeMillis() - it < 5000);
                Log.w("Executing coroutine", "Task3")
            }
            Log.w("Executing coroutine", "All tasks completed")
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions