forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFutureValue.cs
51 lines (40 loc) · 1.44 KB
/
FutureValue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace NHibernate.Impl
{
//Since 5.2
[Obsolete]
internal class FutureValue<T> : IFutureValue<T>, IDelayedValue
{
public delegate IEnumerable<T> GetResult();
public delegate Task<IEnumerable<T>> GetResultAsync(CancellationToken cancellationToken);
private readonly GetResult _getResult;
private readonly GetResultAsync _getResultAsync;
public FutureValue(GetResult result, GetResultAsync resultAsync)
{
_getResult = result;
_getResultAsync = resultAsync;
}
public T Value => _getResult().FirstOrDefault();
public async Task<T> GetValueAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var result = await _getResultAsync(cancellationToken).ConfigureAwait(false);
return result.FirstOrDefault();
}
public Delegate ExecuteOnEval { get; set; }
public IList TransformList(IList collection)
{
if (ExecuteOnEval == null)
return collection;
// When not null on a future value, ExecuteOnEval is fetched with PostExecuteTransformer from
// IntermediateHqlTree through ExpressionToHqlTranslationResults, which requires a IQueryable
// as input and directly yields the scalar result when the query is scalar.
var resultElement = (T) ExecuteOnEval.DynamicInvoke(collection.AsQueryable());
return new List<T> {resultElement};
}
}
}