internal static Future <Dictionary <Type, object> > _loadAll( Locale locale, IEnumerable <LocalizationsDelegate> allDelegates) { Dictionary <Type, object> output = new Dictionary <Type, object>(); List <_Pending> pendingList = null; HashSet <Type> types = new HashSet <Type>(); List <LocalizationsDelegate> delegates = new List <LocalizationsDelegate>(); foreach (LocalizationsDelegate del in allDelegates) { if (!types.Contains(del.type) && del.isSupported(locale)) { types.Add(del.type); delegates.Add(del); } } foreach (LocalizationsDelegate del in delegates) { Future <object> inputValue = del.load(locale).to <object>(); object completedValue = null; Future <object> futureValue = inputValue.then_(value => { completedValue = value; return(FutureOr.value(completedValue)); }).to <object>(); if (completedValue != null) { Type type = del.type; D.assert(!output.ContainsKey(type)); output[type] = completedValue; } else { pendingList = pendingList ?? new List <_Pending>(); pendingList.Add(new _Pending(del, futureValue)); } } if (pendingList == null) { return(new SynchronousFuture <Dictionary <Type, object> >(output)); } return(Future.wait <object>(LinqUtils <Future <object>, _Pending> .SelectList(pendingList, (p => p.futureValue))) .then(values => { var list = (List <object>)values; D.assert(list.Count == pendingList.Count); for (int i = 0; i < list.Count; i += 1) { Type type = pendingList[i].del.type; D.assert(!output.ContainsKey(type)); output[type] = list[i]; } return output; }).to <Dictionary <Type, object> >()); }
internal static IPromise <Dictionary <Type, object> > _loadAll(Locale locale, IEnumerable <LocalizationsDelegate> allDelegates) { Dictionary <Type, object> output = new Dictionary <Type, object>(); List <_Pending> pendingList = null; HashSet <Type> types = new HashSet <Type>(); List <LocalizationsDelegate> delegates = new List <LocalizationsDelegate>(); foreach (LocalizationsDelegate del in allDelegates) { if (!types.Contains(del.type) && del.isSupported(locale)) { types.Add(del.type); delegates.Add(del); } } foreach (LocalizationsDelegate del in delegates) { IPromise <object> inputValue = del.load(locale); object completedValue = null; IPromise <object> futureValue = inputValue.Then(value => { return(completedValue = value); }); if (completedValue != null) { Type type = del.type; D.assert(!output.ContainsKey(type)); output[type] = completedValue; } else { pendingList = pendingList ?? new List <_Pending>(); pendingList.Add(new _Pending(del, futureValue)); } } if (pendingList == null) { return(Promise <Dictionary <Type, object> > .Resolved(output)); } return(Promise <object> .All(pendingList.Select(p => p.futureValue)) .Then(values => { var list = values.ToList(); D.assert(list.Count == pendingList.Count); for (int i = 0; i < list.Count; i += 1) { Type type = pendingList[i].del.type; D.assert(!output.ContainsKey(type)); output[type] = list[i]; } return output; })); }