private TData LoadingForwarder <TData>(Func <IStringLocalizer, TData> handler)
        {
            lock (this.syncObject)
            {
                if (!this.loaded)
                {
                    var completed = false;
                    lock (PendingAsyncLocalizers)
                    {
                        if (this.loadingTask.Status == TaskStatus.RanToCompletion && PendingAsyncLocalizers.ContainsKey(this.stringLocalizerGuid))
                        {
                            PendingAsyncLocalizers.Remove(this.stringLocalizerGuid);
                            completed = true;
                        }
                    }

                    if (completed)
                    {
                        var map = this.loadingTask.Result;

                        if (map != null)
                        {
                            this.stringLocalizer = new JsonStringLocalizer(map, this.cultureInfo, this.localizerFactory);
                        }

                        this.loaded = true;
                    }
                }

                return(handler(this.stringLocalizer));
            }
        }
        /// <summary>
        /// Setup the asynchronous StringLocalizer.
        /// </summary>
        /// <param name="loadingTask">Asynchronous loading task.</param>
        /// <param name="cultureInfo">The associated culture info.</param>
        /// <param name="localizerFactory">Localizer Internal Factory.</param>
        /// <param name="loadingLocalizer">Localizer to use while loading asynchronously.</param>
        public JsonStringLocalizerAsync(Task <IReadOnlyDictionary <string, string>?> loadingTask, CultureInfo cultureInfo, IJsonStringLocalizerFactoryInternal localizerFactory, IStringLocalizer loadingLocalizer)
        {
            this.loadingTask = loadingTask;
            this.cultureInfo = cultureInfo;
            this.loaded      = false;

            this.localizerFactory = localizerFactory ?? throw new ArgumentNullException(nameof(localizerFactory));

            if (this.loadingTask.Status == TaskStatus.RanToCompletion)
            {
                var map = this.loadingTask.Result;

                if (map != null)
                {
                    this.stringLocalizer = new JsonStringLocalizer(map, this.cultureInfo, this.localizerFactory);
                }
                else
                {
                    this.stringLocalizer = new NullStringLocalizer(cultureInfo, this.localizerFactory, true);
                }

                this.loaded = true;
            }
            else
            {
                this.stringLocalizer = loadingLocalizer;

                lock (PendingAsyncLocalizers)
                {
                    PendingAsyncLocalizers.Add(this.stringLocalizerGuid, this);
                }
            }
        }