aliyun / aliyun-oss-csharp-sdk

Aliyun OSS SDK for C#
MIT License
383 stars 206 forks source link

Is this SDK for Javascript? No Async/Await #116

Open GiddyNaya opened 4 years ago

GiddyNaya commented 4 years ago

There is literally no Async/Await interface for operations. This definitely kills the whole essence of having an SDK for netcore. Individual methods with Begin... End... (What is this?) It really makes no sense!

It's only in Java or Javascript we have the need to pass callbacks to methods. In C# netcore we use Async/Await, hence when a task is completed it returns the expected result and we make use of it, not the other way round.

We really need the team to build the interfaces like it was meant for C# developers. Thank you.

This is wrong (Begin... & End...)

        /// <inheritdoc/>
        public IAsyncResult BeginCopyObject(CopyObjectRequest copyObjectRequst, AsyncCallback callback, Object state)
        {
            ThrowIfNullRequest(copyObjectRequst);

            var cmd = CopyObjectCommand.Create(_serviceClient, _endpoint,
                                              CreateContext(HttpMethod.Put, copyObjectRequst.DestinationBucketName, copyObjectRequst.DestinationKey),
                                              copyObjectRequst);
            return OssUtils.BeginOperationHelper(cmd, callback, state);
        }

        /// <inheritdoc/>
        public CopyObjectResult EndCopyResult(IAsyncResult asyncResult)
        {
            return OssUtils.EndOperationHelper<CopyObjectResult>(_serviceClient, asyncResult);
        }

This is what we expect (Async/Await)

        /// <inheritdoc/>
        public async Task<CopyObjectResult> CopyObjectAsync(CopyObjectRequest copyObjectRequst)
        {
            ThrowIfNullRequest(copyObjectRequst);

            var cmd = CopyObjectCommand.Create(_serviceClient, _endpoint,
                                              CreateContext(HttpMethod.Put, copyObjectRequst.DestinationBucketName, copyObjectRequst.DestinationKey),
                                              copyObjectRequst);
            return await OssUtils.ProccessCommandAsync<CopyObjectResult>(cmd);
        }
LeaFrock commented 2 years ago

You can follow this repo. The underlying layer uses HttpClient so the surface APIs are async.

You can search AlibabaCloud.SDK.Oss20190517 on Nuget。

kyo8598CC commented 3 months ago

连个async/await都没有 还是回调的异步 真的搞笑