Skip to content

Instantly share code, notes, and snippets.

@jonwis
Created December 3, 2025 17:20
Show Gist options
  • Select an option

  • Save jonwis/5914252720ac77c12d1e90d3fe66ec71 to your computer and use it in GitHub Desktop.

Select an option

Save jonwis/5914252720ac77c12d1e90d3fe66ec71 to your computer and use it in GitHub Desktop.
Sample Try... pattern like HttpClient
// C++ caller
void DownloadTheThing(Thing const& thing) {
auto op { thing.DownloadAsync(L"arg1", L"arg2") };
op.Progress([](auto const &pending, uint32_t progress) {
// Handle progress update
wprintf(L"Download progress: %u%%\n", progress);
});
var result = op.get(); // Await completion
if (result.StatusIsSuccess) {
// use result.Result
} else if (result.Status == ThingDownloadStatus::NotFound) {
// whoops, try another set of args
} else if (result.Status == ThingDownloadStatus::TooManyKittens) {
// oh no, handle kitten overload
} else {
// generic error handling
wprintf(L"Download failed with error: 0x%08X, message: %s\n", result.ExtendedError, result.Message.c_str());
}
}
// MIDL3 definition
// Note that ThingDownloadStatus aligns with standard HTTP error codes AND well-known
// service response values
enum ThingDownloadStatus {
Success = 200,
NotFound = 404,
ServerError = 500,
TooManyKittens = 1005,
InsufficientPancakes = 1006
};
runtimeclass ThingDownloadResult {
ThingDownloadStatus Status;
Boolean StatusIsSuccess { get; };
String Message;
HRESULT ExtendedError;
IVector<String> Result;
}
runtimeclass Thing {
IAsyncOperationWithProgress<ThingDownloadResult, UInt32> DownloadAsync(String args, String args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment