---
title: "Comment by Marek Langiewicz on \"Coroutines racing! Why, and how.\" | Hashnode"
description: "Louis CAD A (fixed) basic approach ;-) suspend fun awaitTrigger1 () { coroutineScope { val win = coroutineContext::cancelChildren launch { awaitAutomaticTrigger"
url: "https://hashnode.com/posts/coroutines-racing-why-and-how/618a2953f991b025366df06f/comment/619798f3df376a260c5876dd"
---

[Discussion](https://hashnode.com/posts/coroutines-racing-why-and-how/618a2953f991b025366df06f)

Comment [Coroutines racing! Why, and how.](https://hashnode.com/posts/coroutines-racing-why-and-how/618a2953f991b025366df06f)

[Marek Langiewicz](https://hashnode.com/@Langara)

[Nov 19, 2021](https://hashnode.com/posts/coroutines-racing-why-and-how/618a2953f991b025366df06f/comment/619798f3df376a260c5876dd)

[Louis CAD](https://hashnode.com/@LouisCAD) A (fixed) basic approach ;-)

```
suspend fun awaitTrigger1() { coroutineScope {
    val win = coroutineContext::cancelChildren
    launch { awaitAutomaticTrigger(); win(null) }
    launch { awaitManualTrigger(); win(null) }
} }
```

version with some result

```
suspend fun awaitTrigger2(): T = coroutineScope {
    val deferred = CompletableDeferred<T>()
    launch { deferred.complete(awaitAutomaticTrigger()) }
    launch { deferred.complete(awaitManualTrigger()) }
    deferred.await().also { coroutineContext.cancelChildren() }
}
```

[pl.kotl.in/i1YWEs2lC](https://pl.kotl.in/i1YWEs2lC) [pl.kotl.in/oQyBHb2bg](https://pl.kotl.in/oQyBHb2bg)

[Louis CAD](https://hashnode.com/@LouisCAD)

[Nov 27, 2021](https://hashnode.com/posts/coroutines-racing-why-and-how/618a2953f991b025366df06f/comment/619798f3df376a260c5876dd#reply-61a23c16a707ae38156d6111)

That one is a good alternative. It's not immune to late racers (so, the use case of `race` rather than `raceOf`), but I believe it's possible to make some edits that make it supported and thread-safe for this use case.

Now I'm wondering what would perform best between your snippet and using select.
