Example #1
0
    /// <summary>
    /// Look for profile in userProfilesCatalog or request kernel for a profile if not available
    /// </summary>
    /// <param name="userId">id of profile to fetch</param>
    /// <returns>a promise of the user profile</returns>
    public Promise <UserProfile> FetchProfile(string userId)
    {
        Promise <UserProfile> promise = new Promise <UserProfile>();

        if (UserProfileController.userProfilesCatalog.TryGetValue(userId, out UserProfile profile))
        {
            promise.Resolve(profile);
            return(promise);
        }

        if (!pendingPromises.TryGetValue(userId, out List <Promise <UserProfile> > promisesForUserId))
        {
            promisesForUserId = new List <Promise <UserProfile> >();
            pendingPromises.Add(userId, promisesForUserId);
            WebInterface.RequestUserProfile(userId);
        }

        promisesForUserId.Add(promise);
        return(promise);
    }