# Best way to create an async child workflow

**URL:** https://community.temporal.io/t/best-way-to-create-an-async-child-workflow/114
**Category:** Community Support
**Tags:** child-workflow, async
**Created:** [July 8, 2020, 8:01pm UTC](https://community.temporal.io/t/best-way-to-create-an-async-child-workflow/114 "2020-07-08T20:01:01Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [July 8, 2020, 9:18pm UTC](https://community.temporal.io/t/best-way-to-create-an-async-child-workflow/114/2 "2020-07-08T21:18:32Z")

</div>

Currently, it is not straightforward. We have plans to improve the experience ([relevant issue](https://github.com/temporalio/temporal-java-sdk/issues/74)), but in the meantime, the following should be done.

## Java SDK

1. Set `ChildWorkflowOptions.ParentClosePolicy` to `ABANDON` when creating a child workflow stub.
2. Start child workflow asynchronously using Async.function or Async.procedure.
3. Call Workflow.getWorkflowExecution(…) on the child stub
4. Wait for the `Promise` returned by `getWorkflowExecution` to complete. This indicates that the child successfully started (or start failed).
5. Complete parent workflow.

Steps 3 and 4 are needed to ensure that child workflow starts before the parent closes. If the parent initiates child workflow and immediately completes the child would never start. Here is the code that demonstrates the steps:

```auto
   public void parentWorklfow() {
       ChildWorkflowOptions options =
          ChildWorkflowOptions.newBuilder()
              .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
              .build();
       MyChildWorkflow child = Workflow.newChildWorkflowStub(MyChildWorkflow.class, options);
       Async.procedure(child::<workflowMethod>, <args>...);
       Promise<WorkflowExecution> childExecution = Workflow.getWorkflowExecution(child);
       // Wait for child to start
       childExecution.get()
  }

```

## Go SDK

1. Set `ChildWorkflowOptions.ParentClosePolicy` to `ABANDON` when creating a child workflow stub.
2. Start child workflow using ExecuteChildWorkflow
3. Call GetChildWorkflowExecution on the ChildWorkflowFuture returned by the ExecuteChildWorkflow
4. Wait on the WorkflowExecution Future. This indicates that the child successfully started (or start failed).
5. Complete parent workflow

Steps 3 and 4 are needed to ensure that child workflow starts before the parent closes. If the parent initiates child workflow and immediately completes the child would never start. Here is the code that demonstrates the steps (error handling omitted for brevity):

```auto
func ParentWorkflow(ctx workflow.Context) error {
    childWorkflow := workflow.ExecuteChildWorkflow(ctx, MyChildWorkflow)
    // Wait for child to start
    _ = childWorkflow.GetChildWorkflowExecution().Get(ctx, nil)
    return nil
}

```

---

_[View the full topic](https://community.temporal.io/t/best-way-to-create-an-async-child-workflow/114)._
