示例#1
0
    public static bool TryAddAsyncLazy <T>(this ConcurrentTypeSet <object> set, Func <Task <T> > valueFactory)
    {
        Contracts.Requires.That(set != null);
        Contracts.Requires.That(valueFactory != null);

        return(set.TryAdd(new AsyncLazy <T>(valueFactory)));
    }
示例#2
0
    public static async Task <T> GetOrAddLazyAsync <T>(this ConcurrentTypeSet <object> set, Func <Task <T> > valueFactory)
    {
        Contracts.Requires.That(set != null);
        Contracts.Requires.That(valueFactory != null);

        return(await set.GetOrAdd(new AsyncLazy <T>(valueFactory)));
    }
示例#3
0
    public static T GetOrAddLazy <T>(this ConcurrentTypeSet <object> set, Func <T> valueFactory)
    {
        Contracts.Requires.That(set != null);
        Contracts.Requires.That(valueFactory != null);

        return(set.GetOrAdd(new Lazy <T>(valueFactory)).Value);
    }
示例#4
0
    public static async Task <TryValue <T> > TryGetValueLazyAsync <T>(this ConcurrentTypeSet <object> set)
    {
        Contracts.Requires.That(set != null);

        AsyncLazy <T> lazy;

        return(set.TryGetValue(out lazy) ? TryValue.New(await lazy) : TryValue.None <T>());
    }
示例#5
0
    public static bool TryGetValueLazy <T>(this ConcurrentTypeSet <object> set, out T value)
    {
        Contracts.Requires.That(set != null);

        Lazy <T> lazy;
        bool     result = set.TryGetValue(out lazy);

        value = lazy.Value;
        return(result);
    }
示例#6
0
    public static async Task <T> AddOrUpdateLazyAsync <T>(
        this ConcurrentTypeSet <object> set, Func <Task <T> > addValueFactory, Func <T, T> updateValueFactory)
    {
        Contracts.Requires.That(set != null);
        Contracts.Requires.That(addValueFactory != null);
        Contracts.Requires.That(updateValueFactory != null);

        return(await set.AddOrUpdate(
                   new AsyncLazy <T>(addValueFactory),
                   old => new AsyncLazy <T>(async() => updateValueFactory(await old))));
    }
示例#7
0
    public static T AddOrUpdateLazy <T>(
        this ConcurrentTypeSet <object> set, Func <T> addValueFactory, Func <T, T> updateValueFactory)
    {
        Contracts.Requires.That(set != null);
        Contracts.Requires.That(addValueFactory != null);
        Contracts.Requires.That(updateValueFactory != null);

        return(set.AddOrUpdate(
                   new Lazy <T>(addValueFactory),
                   old => new Lazy <T>(() => updateValueFactory(old.Value))).Value);
    }
示例#8
0
    public static bool TryRemoveAsyncLazy <T>(this ConcurrentTypeSet <object> set)
    {
        Contracts.Requires.That(set != null);

        return(set.TryRemove <AsyncLazy <T> >());
    }