Interface IEventSource
This interface defines the public members of EventSource.
Namespace: LaunchDarkly.EventSource
Assembly: LaunchDarkly.EventSource.dll
Syntax
public interface IEventSource
Properties
| Edit this page View SourceReadyState
Gets the state of the EventSource connection.
Declaration
ReadyState ReadyState { get; }
Property Value
| Type | Description |
|---|---|
| ReadyState |
Methods
| Edit this page View SourceClearTemporaryRetryDelayBounds()
Discards any bounds installed by
SetTemporaryRetryDelayBounds(TimeSpan, TimeSpan), restoring the configured
MaxRetryDelay(TimeSpan) and, unless a server-directed
retry: value is in effect, the configured
InitialRetryDelay(TimeSpan).
Declaration
void ClearTemporaryRetryDelayBounds()
Remarks
Restoring the configured bounds resets the backoff level. If no temporary bounds are in effect this does nothing. The count of reconnection attempts is not reset. Calling this is not required as the configured bounds are also restored automatically after a connection stays open for BackoffResetThreshold(TimeSpan).
A server-directed reconnection time received via the SSE retry: field is not
discarded and continues to supersede
InitialRetryDelay(TimeSpan), so the configured
minimum may not be the one actually in use afterwards. Only a later retry: value
replaces it. MaxRetryDelay(TimeSpan) is unaffected
and is always restored.
See Also
| Edit this page View SourceClose()
Closes the connection to the SSE server. The EventSource cannot be reopened after this.
Declaration
void Close()
Restart(bool)
Triggers the same "close and retry" behavior as if an error had been encountered on the stream.
Declaration
void Restart(bool resetBackoffDelay)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | resetBackoffDelay | true if the delay before reconnection should be reset to the lowest level of the currently active bounds, which could be the temporary bounds if SetTemporaryRetryDelayBounds(TimeSpan, TimeSpan) is in effect; false if it should increase according to the usual exponential backoff logic |
Remarks
If the stream is currently active, this closes the connection, waits for some amount of time
as determined by the usual backoff behavior (and resetBackoffDelay), and
then attempts to reconnect. If the stream is not yet connected, is already waiting to
reconnect, or has been permanently shut down, this has no effect.
The method returns immediately without waiting for the reconnection to happen. You will receive Closed and Opened events when it does happen (or an Error event if the new connection attempt fails).
SetTemporaryRetryDelayBounds(TimeSpan, TimeSpan)
Temporarily replaces the bounds used to compute reconnection delays.
Declaration
void SetTemporaryRetryDelayBounds(TimeSpan initialDelay, TimeSpan maxDelay)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | initialDelay | the lowest delay to use while these bounds are in effect,
unless a server-directed |
| TimeSpan | maxDelay | the highest delay to use while these bounds are in effect |
Remarks
The configured InitialRetryDelay(TimeSpan) and
MaxRetryDelay(TimeSpan) normally govern the
exponential backoff between reconnection attempts. This method installs different
bounds at runtime, so a caller can slow reconnection down without reconfiguring or
recreating the EventSource.
The bounds are temporary: they remain in effect until either a connection stays open for at least BackoffResetThreshold(TimeSpan), at which point the configured bounds are restored automatically, or ClearTemporaryRetryDelayBounds() is called.
Changing the bounds resets the backoff level, so the next delay is computed from the new
initialDelay rather than continuing to grow from where it left off.
Calling this with bounds that are already in effect does nothing, so it is safe to call
repeatedly.
Negative values are changed to zero. If initialDelay is greater than
maxDelay, delays are limited to maxDelay. No
argument causes this method to throw, and no argument can cause a later reconnect to
fail.
A server-directed reconnection time received via the SSE retry: field supersedes
initialDelay, and the configured
InitialRetryDelay(TimeSpan) along with it. Such a
value does not affect maxDelay, so the ceiling set here continues to
bound reconnection.
It is safe to call this from any thread, including from an Error handler.
See Also
| Edit this page View SourceStartAsync()
Initiates a connection to the SSE server and begins parsing events.
Declaration
Task StartAsync()
Returns
| Type | Description |
|---|---|
| Task | a Task that will be completed only when the
|
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | if the method was called again after the stream connection was already active |
Events
| Edit this page View SourceClosed
Occurs when the connection to the EventSource API has been closed.
Declaration
event EventHandler<StateChangedEventArgs> Closed
Event Type
| Type | Description |
|---|---|
| EventHandler<StateChangedEventArgs> |
CommentReceived
Occurs when a comment has been received from the EventSource API.
Declaration
event EventHandler<CommentReceivedEventArgs> CommentReceived
Event Type
| Type | Description |
|---|---|
| EventHandler<CommentReceivedEventArgs> |
Error
Occurs when an error has happened when the EventSource is open and processing Server Sent Events.
Declaration
event EventHandler<ExceptionEventArgs> Error
Event Type
| Type | Description |
|---|---|
| EventHandler<ExceptionEventArgs> |
MessageReceived
Occurs when a Server Sent Event from the EventSource API has been received.
Declaration
event EventHandler<MessageReceivedEventArgs> MessageReceived
Event Type
| Type | Description |
|---|---|
| EventHandler<MessageReceivedEventArgs> |
Opened
Occurs when the connection to the EventSource API has been opened.
Declaration
event EventHandler<StateChangedEventArgs> Opened
Event Type
| Type | Description |
|---|---|
| EventHandler<StateChangedEventArgs> |