Esempio n. 1
0
        public override Haxl ToHaxlFetch(string bindTo, Scope parentScope)
        {
            var childScope = new Scope(parentScope);
            var binds      = List.Select(Bind).ToList();
            var fetches    = binds.Select((f, i) => f.ToHaxlFetch($"{bindTo}[{i}]", childScope)).ToList();
            var concurrent = fetches.Aggregate((f1, f2) => f1.Applicative(f2));

            return(concurrent.Bind(scope => Haxl.FromFunc((cache, logger) => Done.New(_ =>
            {
                var values = scope.ShallowValues.Select(v => (B)v).ToList();
                return scope.WriteParent(bindTo, values);
            }
                                                                                      ))));
        }
Esempio n. 2
0
        public override Haxl ToHaxlFetch(string bindTo, Scope scope)
        {
            Func <Task <object>, Haxl> DoneFromTask =
                t => Haxl.FromFunc((c, l) => Done.New(_ => scope.Add(bindTo, WarnIfNull(t.Result, l))));

            return(Haxl.FromFunc((cache, logger) =>
            {
                var cacheResult = cache.Lookup(request);
                return cacheResult.Match <Result>
                (
                    notFound =>
                {
                    var blocked = new BlockedRequest(request, request.GetType(), bindTo);
                    cache.Insert(request, blocked);
                    return Blocked.New(
                        new List <BlockedRequest> {
                        blocked
                    },
                        DoneFromTask(blocked.Resolver.Task)
                        );
                },
                    found =>
                {
                    var task = found.Resolver.Task;
                    if (task.IsCompleted)
                    {
                        return Done.New(_ =>
                        {
                            var result = task.Result;
                            return scope.Add(bindTo, WarnIfNull(result, logger));
                        });
                    }
                    return Blocked.New(
                        new List <BlockedRequest>(),
                        DoneFromTask(task)
                        );
                }
                );
            }));
        }
Esempio n. 3
0
 public override Haxl ToHaxlFetch(string bindTo, Scope scope)
 {
     return(Haxl.FromFunc((cache, logger) => Done.New(_ => scope.Add(bindTo, Value))));
 }