X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=ts%2Fstructs%2FEventsProvider.mts;h=e9600685947f2af65a11fd77bbfb3a2f11671844;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hp=cd00f5e752526564b7f091fe1935c5769b622844;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a;p=ldk-java diff --git a/ts/structs/EventsProvider.mts b/ts/structs/EventsProvider.mts index cd00f5e7..e9600685 100644 --- a/ts/structs/EventsProvider.mts +++ b/ts/structs/EventsProvider.mts @@ -280,11 +280,17 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** An implementation of EventsProvider */ export interface EventsProviderInterface { + /**Processes any events generated since the last call using the given event handler. + * + * Subsequent calls must only process new events. However, handlers must be capable of handling + * duplicate events across process restarts. This may occur if the provider was recovered from + * an old state (i.e., it hadn't been successfully persisted after processing pending events). + */ process_pending_events(handler: EventHandler): void; } @@ -292,6 +298,32 @@ class LDKEventsProviderHolder { held: EventsProvider; } +/** + * A trait indicating an object may generate events. + * + * Events are processed by passing an [`EventHandler`] to [`process_pending_events`]. + * + * # Requirements + * + * See [`process_pending_events`] for requirements around event processing. + * + * When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending + * event since the last invocation. The handler must either act upon the event immediately + * or preserve it for later handling. + * + * Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to + * consult the provider's documentation on the implication of processing events and how a handler + * may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and + * [`ChainMonitor::process_pending_events`]). + * + * (C-not implementable) As there is likely no reason for a user to implement this trait on their + * own type(s). + * + * [`process_pending_events`]: Self::process_pending_events + * [`handle_event`]: EventHandler::handle_event + * [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events + * [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events + */ export class EventsProvider extends CommonBase { /* @internal */ public bindings_instance?: bindings.LDKEventsProvider; @@ -302,7 +334,8 @@ export class EventsProvider extends CommonBase { this.bindings_instance = null; } - static new_impl(arg: EventsProviderInterface): EventsProvider { + /** Creates a new instance of EventsProvider from a given implementation */ + public static new_impl(arg: EventsProviderInterface): EventsProvider { const impl_holder: LDKEventsProviderHolder = new LDKEventsProviderHolder(); let structImplementation = { process_pending_events (handler: number): void { @@ -317,6 +350,14 @@ export class EventsProvider extends CommonBase { impl_holder.held.bindings_instance = structImplementation; return impl_holder.held; } + + /** + * Processes any events generated since the last call using the given event handler. + * + * Subsequent calls must only process new events. However, handlers must be capable of handling + * duplicate events across process restarts. This may occur if the provider was recovered from + * an old state (i.e., it hadn't been successfully persisted after processing pending events). + */ public process_pending_events(handler: EventHandler): void { bindings.EventsProvider_process_pending_events(this.ptr, handler == null ? 0 : CommonBase.get_ptr_of(handler)); CommonBase.add_ref_from(this, handler);