ValueTaskSupplement, an extensions to ValueTask

I have released the new ValueTaskSupplement library.

This release adds WhenAny, WhenAll, and Lazy to ValueTask.

The need for this library can be understood from the relationship between Task and ValueTask, and the appearance of IValueTaskSource.

Task and ValueTask

At the time of its appearance, ValueTask was T | Task [T], which wrapped T if the content was synchronous, and Task if asynchronous. Therefore, the proper use of Task vs. ValueTask was considered to be based on Task conforming to the standard definition, with wrapping unnecessary when the content is confirmed to be asynchronous.

In the pursuit of further performance, IValueTaskSource was introduced to eliminate the overhead of ValueTask-> Task conversion, and to insert code specialized for particular content. With this, ValueTask becomes a union that has one of the states of T | Task [T] | IValueTaskSource, and in individually implemented scenarios, performance is higher when the content is IValueTaskSource than when it is Task [T]. Accordingly, the era of ValueTask has arrived, in both name and reality.

Latest coreclr draft(2019–08–22), Make “async ValueTask/ValueTask<T>” methods ammortized allocation-free will change the common sense of Task and ValueTask.

In actual adoption in applications, it is nearly impossible to think through the proper separation of use every time, and as a basic rule, it is necessary to lay out rules that standardize on one of the two in principle. The appearance of IValueTaskSource should become a major tailwind behind the standardization on ValueTask.

The UniTask library that I created exists in Unity. This is a close substitute for ValueTask + IValueTaskSource.

Lack of ValueTask

Therefore, based on the idea that using IValueTaskSource to create native WhenAll and WhenAny for ValueTask should achieve both an easy-to-use API and high performance, ValueTaskSupplement offers this.

Functions that are even more convenient than just Task.WhenAll/WhenAny, such as WhenAll with different types that depend on tuple, have been added, which should make it easy to standardize on ValueTask.

I hope you will give ValueTaskSupplement a try.

Written by

a.k.a. neuecc. Creator of UniRx, UniTask, MessagePack for C#, MagicOnion etc. Microsoft MVP for C#. CEO/CTO of Cysharp Inc. Live and work in Tokyo, Japan.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store