I have an API that exposes some events when its internal data changes. When someone wants to watch for data change, it attaches an event callback and API notifies it when the data changes internally.
When state is changed and someone initializes code that needs to know current API state and be notified on changes, the event listener needs to be attached and some getter needs to be invoked on API to get the current state.
I'm thinking about making such thing: when you attach an listener, and the state is already known inside API, call the attached callback immediately with the current state and later on, when the state changes.
But the issue is i cannot find a proper design pattern for such behaviour. It seems like an Observer but mutated - it would notify immediately after listener attach if there is anything to inform about.
Please guide me if it makes any sense or its an anti-pattern in general and i should always use initial getter to get current state and "changed" events for future state changes.