# How to start workflow or await on results of a running one

**URL:** <https://community.temporal.io/t/how-to-start-workflow-or-await-on-results-of-a-running-one/10138>\
**Category:** Community Support\
**Tags:** general-impl\
**Created:** [November 17, 2023, 5:33pm UTC](https://community.temporal.io/t/how-to-start-workflow-or-await-on-results-of-a-running-one/10138 "2023-11-17T17:33:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yunmanger](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yunmanger/32/4559_2.png) [@yunmanger](https://community.temporal.io/u/yunmanger)\
**Post date:** [November 17, 2023, 5:33pm UTC](https://community.temporal.io/t/how-to-start-workflow-or-await-on-results-of-a-running-one/10138/1 "2023-11-17T17:33:50Z")

</div>

I have a simple workflow that returns Google credentials. I want to ensure that only one of these workflows is running at the same time (user is asked once) but many other workflows can run it and await on the result of it.

It seems there is no way to subscribe on a running workflow. If I run it as Workflow.newChildWorkflowStub then it fails with an error that workflow `WorkflowExecutionAlreadyStarted` when there is a running one. Should I use some kind of proxy workflows or activities to get similar results. How would it look like?

```auto
class GetGoogleCredentialsWorkflowImpl : GetGoogleCredentialsWorkflow {
    private val userActivities = activities<UserActivities>()
    private var codesMap = mutableMapOf<Long, String>()

    // workflow method
    override fun getCredentials(userId: Long): GoogleCredentials? {
        val credentials: GoogleCredentials? = userActivities.getGoogleCredentials(userId)
        val now = Workflow.currentTimeMillis()
        return if (credentials == null || credentials.expired(now)) {
            userActivities.sendAuthorizationLinkToUser(userId)
            Workflow.await(Duration.ofHours(24)) { codesMap.containsKey(userId) }
            userActivities.processAuthorizationCode(userId, codesMap[userId]!!)
        } else {
            credentials
        }
    }

    // workflow signal
    override fun processCode(userId: Long, code: String) {
        codesMap[userId] = code
    }
}

```

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 17, 2023, 9:39pm UTC](https://community.temporal.io/t/how-to-start-workflow-or-await-on-results-of-a-running-one/10138/2 "2023-11-17T21:39:23Z")

</div>

We plan to add the [ability to wait for an external workflow](https://github.com/temporalio/temporal/issues/680) in the future. If the workflow is not long running you can wait using an activity. Another option is for the workflow to signal all waiting workflows before completion. This assumes that workflows register themselves through another signal.

---

<div class="post-metadata">

**Author:** ![yunmanger](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yunmanger/32/4559_2.png) [@yunmanger](https://community.temporal.io/u/yunmanger)\
**Post date:** [November 17, 2023, 11:26pm UTC](https://community.temporal.io/t/how-to-start-workflow-or-await-on-results-of-a-running-one/10138/3 "2023-11-17T23:26:51Z")

</div>

Not sure what it takes to implement second scenario you described. how does it look like?

1. `WorkflowThatNeedsCredentials` calls activity `userActivities.requestGoogleCredentials(userId, workflowId)`. passing `workflowId` to send signal back.
2. `WorkflowThatNeedsCredentials` implements reply signal processing and waits on reply
3. `userActivities.requestGoogleCredentials` activity uses `signalWithStart` (we are using activity because can’t run signalWithStart from workflow)
4. Implement GetGoogleCredentialsWorkflow.subscribe(workflowId: String) signal processing
5. GetGoogleCredentialsWorkflow sends signal to all subscribers on return

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 18, 2023, 1:11am UTC](https://community.temporal.io/t/how-to-start-workflow-or-await-on-results-of-a-running-one/10138/4 "2023-11-18T01:11:00Z")

</div>

Yes, this is a precise representation of my proposal.
