How to share waiting state with async function

I've recently started learning how to use Swift concurrency. There is a scenario where I would like to determine if there is a better solution.

There's an async function here, and I want to be able to share the waiting state with different threads. It looks like I'm using RxSwift's share() operator.

Currently I use Task to share the waiting status as following

actor Foo {
    private var task: Task<Int, Never>?
    private var value: Int = 0

    func getValue() async -> Int {
        guard let task else { return value }
        return await task.value
    }

    func refresh() async {
        guard task == nil else { return }
        let task = Task {
            return await SomeNetworkCall()
        }
        self.task = task
        _ = await task.value
        self.task = nil
    }
}

I‘d like to know if there is a better way to solve this situation.

It depends on details, but in simplest case you can just use boolean flag:

actor A {
    var inProgress = false 

    func refresh() async {
        guard !inProgress else { return }
        inProgress = true
        defer { inProgress = false }
        await networkCall()
    }
}

If you need to share work execution result (e.g. deduplication), then Task is a good option.