internal async void Execute(TimeSpan dueTime, TimeSpan period, ValueFunc <CancellationToken, Task <bool> > callback)
            {
                try
                {
                    await System.Threading.Tasks.Task.Delay(dueTime, cancellation.Token).ConfigureAwait(false);

                    while (await callback.Invoke(cancellation.Token).ConfigureAwait(false))
                    {
                        await System.Threading.Tasks.Task.Delay(period, cancellation.Token).ConfigureAwait(false);
                    }
                    TrySetResult(true);
                }
                catch (OperationCanceledException)
                {
                    TrySetResult(false);
                }
                catch (Exception e)
                {
                    TrySetException(e);
                }
                finally
                {
                    cancellation.Dispose();
                }
            }
Exemplo n.º 2
0
 internal TimerCompletionSource(TimeSpan dueTime, TimeSpan period, ValueFunc <CancellationToken, Task <bool> > callback, CancellationToken token)
 {
     cancellation  = CancellationTokenSource.CreateLinkedTokenSource(token);
     this.dueTime  = dueTime;
     this.period   = period;
     this.callback = callback;
     continuation  = Execute;
 }
 public TimelineFunctionGraphModel(ValueFunc func, EnvelopeFunc minFunc, EnvelopeFunc maxFunc, float begin, float end)
 {
     this.func = func;
     this.minFunc = minFunc;
     this.maxFunc = maxFunc;
     this.begin = begin;
     this.end = end;
 }
Exemplo n.º 4
0
 public TimelineFunctionGraphModel(ValueFunc func, EnvelopeFunc minFunc, EnvelopeFunc maxFunc, float begin, float end)
 {
     this.func    = func;
     this.minFunc = minFunc;
     this.maxFunc = maxFunc;
     this.begin   = begin;
     this.end     = end;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of lazy value.
 /// </summary>
 /// <param name="valueFactory">The function used to compute actual value.</param>
 /// <param name="resettable"><see langword="true"/> if previously computed value can be removed and computation executed again when it will be requested; <see langword="false"/> if value can be computed exactly once.</param>
 /// <exception cref="ArgumentException"><paramref name="valueFactory"/> doesn't refer to any method.</exception>
 public AsyncLazy(ValueFunc <Task <T> > valueFactory, bool resettable = false)
 {
     if (valueFactory.IsEmpty)
     {
         throw new ArgumentException(ExceptionMessages.EmptyValueDelegate, nameof(valueFactory));
     }
     this.resettable = resettable;
     factory         = valueFactory;
 }
Exemplo n.º 6
0
 GroupBy <T, TKey, TKeySelector>(
     this NativeArray <T> source,
     ValueFunc <T, TKey> .Struct <TKeySelector> keySelector
     )
     where T : struct
     where TKey : unmanaged, IEquatable <TKey>
     where TKeySelector : struct, IFunc <T, TKey>
 {
     return(source.ToValueSequence().GroupBy(keySelector));
 }
Exemplo n.º 7
0
    void Start()
    {
        var output = new NativeArray <long>(source.Length, Allocator.Persistent);
        var job    = new SelectJob <AddOne> {
            Source = source, Selector = ValueFunc <int, long> .New <AddOne>(), Output = output
        };

        job.Run();
        Debug.Log($"output: ({string.Join(",", output)})");
        output.Dispose();
    }
Exemplo n.º 8
0
 public SequenceToNativeHashMapJob(
     ValueSequence <T, TSource, TSourceEnumerator> source,
     ValueFunc <T, TKey> .Struct <TKeySelector> keySelector,
     ValueFunc <T, TElement> .Struct <TElementSelector> elementSelector,
     ref NativeHashMap <TKey, TElement> output
     )
 {
     this.source          = source;
     this.keySelector     = keySelector;
     this.elementSelector = elementSelector;
     this.output          = output;
 }
Exemplo n.º 9
0
 public ArrayToNativeHashMapJob(
     NativeArray <T> source,
     ValueFunc <T, TKey> .Struct <TKeySelector> keySelector,
     ValueFunc <T, TElement> .Struct <TElementSelector> elementSelector,
     ref NativeHashMap <TKey, TElement> output
     )
 {
     this.source          = source;
     this.keySelector     = keySelector;
     this.elementSelector = elementSelector;
     this.output          = output;
 }
Exemplo n.º 10
0
        GroupBy <T, TSource, TSourceEnumerator, TKey, TKeySelector>(
            this ValueSequence <T, TSource, TSourceEnumerator> source,
            ValueFunc <T, TKey> .Struct <TKeySelector> keySelector
            )
            where T : struct
            where TSource : struct, ISequence <T, TSourceEnumerator>
            where TSourceEnumerator : struct, IEnumerator <T>
            where TKey : unmanaged, IEquatable <TKey>
            where TKeySelector : struct, IFunc <T, TKey>
        {
            var elementSelector = UtilFunctions.SameSelector <T>();
            var resultSelector  = UtilFunctions.GroupSelector <TKey, T>();

            return(source.GroupBy(keySelector, elementSelector, resultSelector));
        }
Exemplo n.º 11
0
        public object GetValue()
        {
            if (Value != null)
            {
                return(Value);
            }

            Func <DataTable <TItem>, object> func = ValueFunc.Compile();

            if (func == null)
            {
                return(string.Empty);
            }

            return(func.Invoke(DataTable));
        }
Exemplo n.º 12
0
        public static void OrderedInsertion()
        {
            var comparer = new ValueFunc <long, long, int>(Compare);
            var list     = new List <long> {
                2L
            };

            list.InsertOrdered(1L, comparer);
            Equal(1L, list[0]);
            Equal(2L, list[1]);

            list = new List <long> {
                1L
            };
            list.InsertOrdered(3L, comparer);
            Equal(1L, list[0]);
            Equal(3L, list[1]);

            list = new List <long> {
                1L, 3L, 7L
            };
            Equal(2L, list.InsertOrdered(4L, comparer));
            list.RemoveRange(0, 0);
        }
Exemplo n.º 13
0
 public IgnoreIndex(ValueFunc <T, TResult> .Struct <TSelector> selector)
 {
     this.selector = selector;
 }
Exemplo n.º 14
0
 private T RemoveFactory(Task <T> task)
 {
     factory = default; //cleanup factory because it may have captured variables and other objects
     return(task.Result);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Applies the specified asynchronous action to each collection element.
 /// </summary>
 /// <typeparam name="T">Type of elements in the collection.</typeparam>
 /// <param name="collection">A collection to enumerate. Cannot be <see langword="null"/>.</param>
 /// <param name="action">An action to applied for each element.</param>
 /// <param name="token">The token that can be used to cancel the enumeration.</param>
 /// <returns>The task representing asynchronous execution of this method.</returns>
 /// <exception cref="OperationCanceledException">The enumeration has been canceled.</exception>
 public static ValueTask ForEachAsync <T>(IEnumerable <T> collection, ValueFunc <T, CancellationToken, ValueTask> action, CancellationToken token = default)
 => NewSequence.ForEachAsync(collection, action, token);
Exemplo n.º 16
0
 /// <summary>
 /// Returns the first element in a sequence that satisfies a specified condition.
 /// </summary>
 /// <typeparam name="T">The type of the elements of source.</typeparam>
 /// <param name="seq">A collection to return an element from.</param>
 /// <param name="filter">A function to test each element for a condition.</param>
 /// <param name="token">The token that can be used to cancel enumeration.</param>
 /// <returns>The first element in the sequence that matches to the specified filter; or empty value.</returns>
 /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
 public static ValueTask <Optional <T> > FirstOrEmptyAsync <T>(IAsyncEnumerable <T> seq, ValueFunc <T, bool> filter, CancellationToken token = default)
     where T : notnull
 => NewSequence.FirstOrEmptyAsync(seq, filter, token);
Exemplo n.º 17
0
 /// <summary>
 /// Applies specified action to each collection element asynchronously.
 /// </summary>
 /// <typeparam name="T">Type of elements in the collection.</typeparam>
 /// <param name="collection">A collection to enumerate. Cannot be <see langword="null"/>.</param>
 /// <param name="action">An action to applied for each element.</param>
 /// <param name="token">The token that can be used to cancel the enumeration.</param>
 /// <returns>The task representing asynchronous execution of this method.</returns>
 /// <exception cref="OperationCanceledException">The enumeration has been canceled.</exception>
 public static async ValueTask ForEachAsync <T>(this IAsyncEnumerable <T> collection, ValueFunc <T, CancellationToken, ValueTask> action, CancellationToken token = default)
 {
     await foreach (var item in collection.WithCancellation(token))
     {
         await action.Invoke(item, token).ConfigureAwait(false);
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Returns the first element in a sequence that satisfies a specified condition.
        /// </summary>
        /// <typeparam name="T">The type of the elements of source.</typeparam>
        /// <param name="seq">A collection to return an element from.</param>
        /// <param name="filter">A function to test each element for a condition.</param>
        /// <param name="token">The token that can be used to cancel enumeration.</param>
        /// <returns>The first element in the sequence that matches to the specified filter; or empty value.</returns>
        /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
        public static async ValueTask <Optional <T> > FirstOrEmptyAsync <T>(this IAsyncEnumerable <T> seq, ValueFunc <T, bool> filter, CancellationToken token = default)
            where T : notnull
        {
            await foreach (var item in seq.WithCancellation(token))
            {
                if (filter.Invoke(item))
                {
                    return(item);
                }
            }

            return(Optional <T> .None);
        }
Exemplo n.º 19
0
 public static ValueFunc <T, T> .Struct <Functions.SelectSelf <T> > SelectSelf <T>() where T : struct =>
 ValueFunc <T, T> .New <Functions.SelectSelf <T> >();
Exemplo n.º 20
0
 internal TWrapper WrapBuffer <TWrapper>(ValueFunc <T[], int, TWrapper> factory)
 => factory.Invoke(buffer, position);