tmenier / AsyncPoco

A long-"awaited" fully asynchronous PetaPoco fork
Other
127 stars 33 forks source link

The meaning of asynchrony #66

Closed mahaisong closed 2 years ago

mahaisong commented 2 years ago

Is it faster than PetaPoco? No. But that's not the point of asynchronous code. The point is to free up threads while waiting on I/O-bound work to complete, making desktop and mobile apps more responsive and web applications more scalable. ————————————————————————————————————————————————

public Task OpenAsync() { return OpenAsync(CancellationToken.None); }

    public virtual Task OpenAsync(CancellationToken cancellationToken)
    {
        TaskCompletionSource<object> taskCompletionSource = new TaskCompletionSource<object>();
        if (cancellationToken.IsCancellationRequested)
        {
            taskCompletionSource.SetCanceled();
        }
        else
        {
            try
            {
                Open();
                taskCompletionSource.SetResult(null);
            }
            catch (Exception exception)
            {
                taskCompletionSource.SetException(exception);
            }
        }

        return taskCompletionSource.Task;
    }
mahaisong commented 2 years ago

Remind everyone