# Child workflows send a signal to the parent

**URL:** https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580
**Category:** Community Support
**Tags:** typescript-sdk
**Created:** [August 4, 2022, 9:46am UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580 "2022-08-04T09:46:19Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![grelo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/grelo/32/2577_2.png) [@grelo](https://community.temporal.io/u/grelo)
#### Post date: [August 4, 2022, 9:46am UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/1 "2022-08-04T09:46:19Z")

</div>

Hi,  
I need to create multiple child workflows in parent workflow and the parent needs to wait for all of the child workflows to be finished.  
Can I send a signal from the child to the parent? Is there any code example in typescript?  
What’s the best patern to wait for all of the child workflows to be finished?

Thanks.

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [August 4, 2022, 2:37pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/2 "2022-08-04T14:37:04Z")

</div>

You can start them async and wait for their completion, similar to [this](https://github.com/temporalio/samples-typescript/blob/main/child-workflows/src/workflows.ts) sample ( `await Promise.all` )

---

<div class="post-metadata">

### Author: ![grelo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/grelo/32/2577_2.png) [@grelo](https://community.temporal.io/u/grelo)
#### Post date: [August 4, 2022, 4:53pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/3 "2022-08-04T16:53:28Z")

</div>

Hi,  
In my use case I can’t wait for all of them, I need to be able to send data back (quering the parent) if any child has finished.  
Is there any way to do this?  
Can I send a signal from the child to notify the parent with the result?

Thanks.

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [August 4, 2022, 5:23pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/4 "2022-08-04T17:23:51Z")

</div>

> Can I send a signal from the child to notify the parent with the result?

Yes, you can get the parent workflow id and runid inside child via:

```auto
workflowInfo().parent?.workflowId;
workflowInfo().parent?.runId;

```

Can you explain your use case please? Would help with knowing if sending signals from child workflows is best option for it or not.

---

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/loren/32/5099_2.png) [@loren](https://community.temporal.io/u/loren)
#### Post date: [August 4, 2022, 5:56pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/5 "2022-08-04T17:56:02Z")

</div>

> I can’t wait for all of them

Why not?

---

<div class="post-metadata">

### Author: ![grelo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/grelo/32/2577_2.png) [@grelo](https://community.temporal.io/u/grelo)
#### Post date: [August 5, 2022, 8:19am UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/6 "2022-08-05T08:19:26Z")

</div>

Hi,  
The child workflows would process some data like, for example, send some external request but that request can take time, like 5-10 minutes. An example would be: the parent creates four children, child one and two process the data stright away but the rest doesn’t(send some request or wait for some external processing that can take 5 - 10 minutes). I would like to have access to that partial results and that’s why I’d like to notify the parent when a child has finished, so I could update some parent state and query it from outside.

Thanks.

---

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/loren/32/5099_2.png) [@loren](https://community.temporal.io/u/loren)
#### Post date: [August 5, 2022, 3:20pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/7 "2022-08-05T15:20:04Z")

</div>

This updates the `results` state whenever a child finishes, but still waits for all of them to complete before returning:

```auto
async function myWorkflow(): Promise<string> {
  let results = [];
  await Promise.all([
    executeChild().then(result => results.push[result]), 
    executeChild().then(result => results.push[result])
  ])
  return 'done'
}

```

---

<div class="post-metadata">

### Author: ![bergundy](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/bergundy/32/900_2.png) [@bergundy](https://community.temporal.io/u/bergundy)
#### Post date: [August 5, 2022, 4:14pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/8 "2022-08-05T16:14:17Z")

</div>

> [@loren](#):
>
> ```auto
> executeChild().then(result => results.push[result]), 
> 
> ```

Should be

```ts
    executeChild().then(result => results.push(result)), 

```

---

<div class="post-metadata">

### Author: ![grelo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/grelo/32/2577_2.png) [@grelo](https://community.temporal.io/u/grelo)
#### Post date: [August 8, 2022, 8:07am UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/9 "2022-08-08T08:07:01Z")

</div>

The main issue here is that I still need to wait for all of them to get the result.  
Could I write some loop or interval checker without getting a non-deterministic error?

---

<div class="post-metadata">

### Author: ![lorensr](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/lorensr/32/1709_2.png) [@lorensr](https://community.temporal.io/u/lorensr)
#### Post date: [August 8, 2022, 3:25pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/10 "2022-08-08T15:25:16Z")

</div>

The Promise.all resolves when you have all the results

---

<div class="post-metadata">

### Author: ![grelo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/grelo/32/2577_2.png) [@grelo](https://community.temporal.io/u/grelo)
#### Post date: [August 9, 2022, 9:34am UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/11 "2022-08-09T09:34:27Z")

</div>

what I need to do is the ability to query the parent while is getting results from children, that’s why promise all won’t work in this case. Is there any pattern that I can use?

---

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/loren/32/5099_2.png) [@loren](https://community.temporal.io/u/loren)
#### Post date: [August 9, 2022, 3:40pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/12 "2022-08-09T15:40:24Z")

</div>

The below query will first return `[]`, then [‘firstresult’], then [‘firstresult’, ‘secondresult’].

```auto
import { executeChild, defineQuery, setHandler } from '@temporalio/workflow';

const getResults = defineQuery<string[]>('getResults');

async function myWorkflow(): Promise<string> {
  let results: string[] = [];

  setHandler(getResults, () => results);

  await Promise.all([
    executeChild().then(result => results.push(result)), 
    executeChild().then(result => results.push(result))
  ]);
  return 'done';
}

```

---

<div class="post-metadata">

### Author: ![grelo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/grelo/32/2577_2.png) [@grelo](https://community.temporal.io/u/grelo)
#### Post date: [August 9, 2022, 5:16pm UTC](https://community.temporal.io/t/child-workflows-send-a-signal-to-the-parent/5580/13 "2022-08-09T17:16:08Z")

</div>

Thanks, this was what I was looking for. I’m gonna try to write some complex workflows to see how it works.
