异步调用后删除指针

时间:2016-12-24 12:00:24

标签: c++ azure visual-c++ concurrency azure-storage

我正在尝试将文件上传到azure存储,我想利用异步功能。但是我很难知道清理是否正确完成。

我想删除文件数据,并释放所有流,但显然应该在上传完成后完成。

关于如何改进它以使其更强大的任何评论?

Concurrency::task<void> BlobService::UploadAsync(
    cloud_blob_container container, const wchar_t* blobName,
    uint8_t * data, size_t dataLength,
    const wchar_t* contentType, const wchar_t* cacheControl) {

    rawptr_buffer<uint8_t>* buffer = new rawptr_buffer<uint8_t>(data, dataLength);
    istream inputStream = buffer->create_istream();

    cloud_block_blob blob = container.get_block_blob_reference(utility::string_t(blobName));
    blob.properties().set_content_type(utility::string_t(contentType));
    blob.properties().set_cache_control(utility::string_t(cacheControl));

    azure::storage::blob_request_options options;
    options.set_maximum_execution_time(std::chrono::seconds(10800));
    options.set_server_timeout(std::chrono::seconds(10800));

    azure::storage::access_condition access;
    azure::storage::operation_context context;

    return blob.upload_from_stream_async(inputStream, access, options, context).then([buffer, inputStream, data] {
        buffer->close().wait();
        inputStream.close().wait();

        delete[] data;
        delete buffer;
    });

}

0 个答案:

没有答案