Event-handling mechanisms

An event-handling mechanism provides a way for one DataBlade® API module to inform another module (or another part of the same module) that an event has occurred during execution of a function.

An event-handling mechanism has two parts:
  • A function that throws an event

    A function in a DataBlade API module might encounter a condition that it cannot handle. Events represent many common conditions (see DataBlade API event types). When a module encounters one of these conditions, it can throw the associated event to indicate that some event handling needs to be performed.

  • A function that catches an event

    A special function, called a callback function, is invoked when its associated event occurs. The callback function can perform the appropriate actions to handle or recover from this event.

This division of event-handling responsibility enables you to put common event-handling code for a particular condition in a single location, in a callback function. Any DataBlade API module that requires the associated event handling can then register this callback function.

When an event occurs, the DataBlade API performs event handling based on whether it finds a registered callback that can catch (or handle) the event, as follows:
  • If a registered callback exists for the event, the DataBlade API invokes this callback.
  • If no registered callback exists for the event, the DataBlade API takes the appropriate default behavior.