# Return in asyncstream's closure

**URL:** <https://forums.kodeco.com/t/return-in-asyncstreams-closure/178272>\
**Category:** Modern Concurrency in Swift\
**Created:** [September 14, 2022, 9:09am UTC](https://forums.kodeco.com/t/return-in-asyncstreams-closure/178272 "2022-09-14T09:09:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpfitzgeraldstephen](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rpfitzgeraldstephen/32/102075_2.png) [@rpfitzgeraldstephen](https://forums.kodeco.com/u/rpfitzgeraldstephen)\
**Post date:** [September 14, 2022, 9:09am UTC](https://forums.kodeco.com/t/return-in-asyncstreams-closure/178272/1 "2022-09-14T09:09:49Z")

</div>

I’d like to ask a question about return in asyncstream. it seems to stop the stream.  
but why I cant get any event like cancelled or finished in continuation.onTermination closure.  
So this means the asyncstream hasnt ended.

```auto
AsyncStream<String> { continuation in
      
      continuation.onTermination = { state in
        switch state {
        case .cancelled:
          print("cancelled")
        case .finished:
          print("finished")
        @unknown default:
          print("unknown")
        }
      }
      
      var countdown = 3
      Timer.scheduledTimer(
        withTimeInterval: 1.0,
        repeats: true
      ) { timer in
        guard countdown > 0 else {
          timer.invalidate()
          continuation.yield(with: .success("🎉 done"))
          continuation.finish()
          return
        }
       
       // here 
      if countdown == 2 {
        return
     }
       
        continuation.yield("\(countdown) loading...")
        countdown -= 1
      }
    }

```

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [September 19, 2022, 2:19pm UTC](https://forums.kodeco.com/t/return-in-asyncstreams-closure/178272/2 "2022-09-19T14:19:37Z")

</div>

please help @icanzilb ?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [October 13, 2022, 1:24pm UTC](https://forums.kodeco.com/t/return-in-asyncstreams-closure/178272/3 "2022-10-13T13:24:06Z")

</div>

@rpfitzgeraldstephen sorry for the delay, do you have a code that shows how you use this stream?
