kdcllc / CometD.NetCore.Salesforce

CometD Salesforce Implementation.
MIT License
45 stars 24 forks source link

Use AsynExpiringLazy from Bet.Extensions library #6

Closed kdcllc closed 5 years ago

kdcllc commented 5 years ago
            var instanceClient = new AsyncExpiringLazy<ForceClient>(async data =>
            {
                if (data.Result == null
                || DateTime.UtcNow > data.ValidUntil.Subtract(TimeSpan.FromSeconds(5)))
                {
                    var authClient = new AuthenticationClient();

                    await authClient.TokenRefreshAsync(RefreshToken, ClientId);
                    var client = new ForceClient(authClient.AccessInfo.InstanceUrl, authClient.ApiVersion, authClient.AccessInfo.AccessToken);

                    return new AsyncExpirationValue<ForceClient>
                    {
                        Result = client,
                        ValidUntil = DateTimeOffset.UtcNow.AddSeconds(10)
                    };
                }

                return data;
            });

            var client = instanceClient.Value().Result;

Part of this update is to introduce a new way of creating ForceClient with Resilience space.

ResilientStreamingClient is prefered now over StreamingClient