# Actor Races

**URL:** <https://forums.swift.org/t/actor-races/60439>\
**Category:** Discussion\
**Tags:** concurrency, actors\
**Created:** [September 22, 2022, 7:52am UTC](https://forums.swift.org/t/actor-races/60439 "2022-09-22T07:52:42Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![drewmccormack](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/drewmccormack/32/9181_2.png) [@drewmccormack](https://forums.swift.org/u/drewmccormack)\
**Post date:** [September 22, 2022, 5:24pm UTC](https://forums.swift.org/t/actor-races/60439/15 "2022-09-22T17:24:25Z")

</div>

The way I have solved that is with a serial queue. You then use an AsyncOperation class to hold the contents of the func, and submit that to the queue. Something like this

```swift
func downloadAndStore(completion: @escaping () -> Void) {
	serialQueue.addOperation(
		AsyncOperation { finishHandler in
		    loadWebResource("data.txt") { download in
		        database.store(download) {
		       	 	completion()
					finishHandler()
		        }
		    }
		}
	)
}

```

There is no AsyncOperation in Cocoa, but the Operation class supports the concept of an async operation, so it is quite easy to make a subclass (eg [LLVS/AsynchronousOperation.swift at master · mentalfaculty/LLVS · GitHub](https://github.com/mentalfaculty/LLVS/blob/master/Sources/LLVS/General/AsynchronousOperation.swift))

How would this look in async/await? I suspect you can do this with AsyncStream ([How do you use AsyncStream to make Task execution deterministic?](https://forums.swift.org/t/how-do-you-use-asyncstream-to-make-task-execution-deterministic/57968)), but it is not really any more elegant than the AsyncOperation approach above, and not that accessible to inexperienced developers.

For this reason, I think it would be nice if actors could take care of the streams, queues or whatever they need to make this happen, so the developer can just write something like this

```swift
actor DataManager {
    func downloadAndStore() atomic {
         let download = await loadWebResource("data.txt")
         await database.store(download)
    }
}

```

---

_[View the full topic](https://forums.swift.org/t/actor-races/60439)._
