Skip to content

Commit c09df40

Browse files
committed
optional path to switch to callback
1 parent 2d00f0c commit c09df40

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

include/aws/crt/io/Stream.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <aws/io/async_stream.h>
1111
#include <aws/io/stream.h>
1212

13-
#include <future>
13+
#include <functional>
1414

1515
namespace Aws
1616
{
@@ -226,9 +226,9 @@ namespace Aws
226226

227227
/**
228228
* Asynchronously read into buffer.
229-
* @return future<bool> - true on success (including EOF/no data available), false on error
229+
* Call onComplete(true) on success (including EOF), or onComplete(false) on error.
230230
*/
231-
virtual std::future<bool> ReadImpl(ByteBuf &buffer) noexcept = 0;
231+
virtual void ReadImpl(ByteBuf &buffer, std::function<void(bool)> onComplete) noexcept = 0;
232232

233233
private:
234234
static void s_Destroy(aws_async_input_stream *stream);

source/io/Stream.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <aws/crt/StlAllocator.h>
77
#include <aws/crt/io/Stream.h>
88
#include <iostream>
9-
#include <thread>
109

1110
#include <aws/io/future.h>
1211
#include <aws/io/stream.h>
@@ -250,17 +249,11 @@ namespace Aws
250249
auto impl = static_cast<AsyncInputStream *>(stream->impl);
251250
auto future = aws_future_bool_new(impl->m_allocator);
252251

253-
std::shared_future<bool> cppFuture = impl->ReadImpl(*dest).share();
254-
255252
aws_future_bool_acquire(future);
256-
std::thread(
257-
[future, cppFuture]()
258-
{
259-
bool result = cppFuture.get();
260-
aws_future_bool_set_result(future, result);
261-
aws_future_bool_release(future);
262-
})
263-
.detach();
253+
impl->ReadImpl(*dest, [future](bool result) {
254+
aws_future_bool_set_result(future, result);
255+
aws_future_bool_release(future);
256+
});
264257

265258
return future;
266259
}

0 commit comments

Comments
 (0)