Suppose I want to implement a method that loads a file asynchronously and returns some task with the file's content as its result. In .NET, I could say:
public async Task<byte[]> GetFileContentsAsync(string path)
{
using (var fs = File.OpenRead(path))
using (var ms = new MemoryStream())
{
await fs.CopyToAsync(ms);
return ms.ToArray();
}
}
Under the covers, CopyToAsync
will utilize IO completion ports to ensure that a thread won't be wasted idling, waiting for IO.
Is there an equivalent in Objective-C(++)? Can I implement the following contract efficiently?
ppl::task<StorageBufferPtr> GetFileContentsAsync(const shared_ptr<string> path)
{
???
}
The documentation you are looking for is here: