Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/wil/winrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,13 @@ namespace details
HRESULT WaitForCompletion(_In_ TIOperation operation, _Out_ TIResults result, COWAIT_FLAGS flags, DWORD timeoutValue, _Out_opt_ bool* timedOut) WI_NOEXCEPT
{
RETURN_IF_FAILED_EXPECTED(details::WaitForCompletion(operation, flags, timeoutValue, timedOut));

// If the caller is listening for timedOut, and we actually timed out, return S_OK.
if (timedOut && *timedOut)
{
return S_OK;
}

return operation->GetResults(result);
}
#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
Expand Down
13 changes: 12 additions & 1 deletion tests/FakeWinRTTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,18 @@ struct FakeAsyncOperation

IFACEMETHODIMP GetResults(Abi* results) override
{
return m_storage.CopyTo(results);
auto lock = m_lock.lock_shared();
switch (m_status)
{
case AsyncStatus::Started:
return E_ILLEGAL_METHOD_CALL;
case AsyncStatus::Completed:
return m_storage.CopyTo(results);
case AsyncStatus::Error:
return m_result;
default:
return E_NOTIMPL;
}
}

// Test functions
Expand Down
14 changes: 14 additions & 0 deletions tests/WinRTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,20 @@ TEST_CASE("WinRTTests::WaitForCompletionTimeout", "[winrt][wait_for_completion]"
REQUIRE(timedOut);
}

TEST_CASE("WinRTTests::WaitForCompletionTimeoutWithResult", "[winrt][wait_for_completion]")
{
auto op = Make<FakeAsyncOperation<bool, boolean>>();
REQUIRE(op);

// The wait_for_completion* functions don't properly deduce the "decayed" async type, so force it here
auto asyncOp = static_cast<IAsyncOperation<bool>*>(op.Get());

boolean result = false;
bool timedOut = false;
REQUIRE_SUCCEEDED(wil::wait_for_completion_or_timeout_nothrow(asyncOp, &result, 1, &timedOut));
REQUIRE(timedOut);
}

// This is not a test method, nor should it be called. This is a compilation-only test.
#pragma warning(push)
#pragma warning(disable : 4702) // Unreachable code
Expand Down