public PresenceService(Options?options, IAuthService authService, ISessionResolver sessionResolver, ILogger <PresenceService>?log = null) { options = options.OrDefault(); Log = log ??= NullLogger <PresenceService> .Instance; AuthService = authService; SessionResolver = sessionResolver; UpdateDelayer = new UpdateDelayer(new UpdateDelayer.Options() { Delay = options.UpdatePeriod, CancellationDelay = TimeSpan.Zero, }); }
protected override async Task RunInternalAsync(CancellationToken cancellationToken) { var session = await SessionResolver.GetSessionAsync(cancellationToken).ConfigureAwait(false); var retryCount = 0; while (!cancellationToken.IsCancellationRequested) { await UpdateDelayer.DelayAsync(retryCount, cancellationToken).ConfigureAwait(false); var success = await UpdatePresenceAsync(session, cancellationToken).ConfigureAwait(false); retryCount = success ? 0 : 1 + retryCount; } }
public virtual void UpdatePresence() => UpdateDelayer.CancelDelays();