> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up return data example

> Set up return data example

This topic provides an example of how to set up return data. If there's custom return data, support it by
using the provider and a custom method so that you can retrieve the created data.

```c++ theme={null}
// Provider Callback
[](XAsyncOp op, const XAsyncProviderData* providerData)
{
    switch(op)
    {
    case XAsyncOp::GetResult:
        memcpy(providerData->buffer, &context->result, sizeof(uint64_t));
        break;

    case XAsyncOp::DoWork:
        context->result = 12345678;
        XAsyncComplete(providerData->async, S_OK, sizeof(uint64_t));
        break;

    // Other cases..
    }
}
```

As explained in the [setup example](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-custom-provider), the provider must first
add support for return data by specifying a buffer
size in [XAsyncComplete](/reference/system/xasyncprovider/functions/xasynccomplete) and filling it out in the
`GetResult` case. After support is added, add a method to
retrieve the result for the caller.

```c++ theme={null}
HRESULT CustomProviderMethodAsyncResult(XAsyncBlock* async, uint64_t* outResult)
{
    return XAsyncGetResult(async, CustomProviderMethodAsync,
        sizeof(uint64_t), outResult, nullptr);
}
```

You can call [XAsyncGetResult](/reference/system/xasyncprovider/functions/xasyncgetresult), but the previous method creates a
readable pairing between the custom provider
method. It automatically converts to the data type that's needed for
the async result. This method is also safe to use within any completion
callback to gather results from the work.

## Reference API documentation

* [XAsyncProvider (API contents)](/reference/system/xasyncprovider/xasyncprovider_members)
  * Functions
    * [XAsyncComplete](/reference/system/xasyncprovider/functions/xasynccomplete)
    * [XAsyncGetResult](/reference/system/xasyncprovider/functions/xasyncgetresult)

## See also

[XAsyncProvider library overview](/build/core-features/common/async/async-libraries/async-library-xasyncprovider)
[Set up custom provider (example)](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-custom-provider)
[Setup invocation methods (example)](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-invocation-methods)
[Set up cancelability (example)](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-cancelability)
[XAsyncProvider](/reference/system/xasyncprovider/xasyncprovider_members)


## Related topics

- [Set up cancelability example](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-cancelability.md)
- [Set up invocation methods example](/build/core-features/common/async/async-libraries/async-library-xasyncprovider-example-setup-invocation-methods.md)
- [XAsyncProvider library overview](/build/core-features/common/async/async-libraries/async-library-xasyncprovider.md)
- [XAsync libraries for asynchronous task programming](/build/core-features/common/async/async-libraries/index.md)
- [Set up async task example](/build/core-features/common/async/async-libraries/async-library-xasync-example-setup-async-task.md)
