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); } )))); }
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) ); } ); })); }
public override Haxl ToHaxlFetch(string bindTo, Scope scope) { return(Haxl.FromFunc((cache, logger) => Done.New(_ => scope.Add(bindTo, Value)))); }