on method

EventEmitterListener on(
  1. String type_update,
  2. FutureOr callback(
    1. UpdateTd update
    ), {
  3. void onError(
    1. Object data
    )?,
})

receive all update data

Implementation

EventEmitterListener on(
    String type_update, FutureOr<dynamic> Function(UpdateTd update) callback,
    {void Function(Object data)? onError}) {
  return event_emitter.on(type_update, null, (Event ev, context) async {
    try {
      if (ev.eventData is TdlibIsolateReceiveData) {
        TdlibIsolateReceiveData tdlibIsolateReceiveData =
            (ev.eventData as TdlibIsolateReceiveData);
        await callback(UpdateTd(
          update: tdlibIsolateReceiveData.updateData,
          client_id: tdlibIsolateReceiveData.clientId,
          client_option: () {
            try {
              TdlibClient? tdlibClient =
                  clients[tdlibIsolateReceiveData.clientId];
              if (tdlibClient != null) {
                return tdlibClient.client_option;
              }
            } catch (e) {}
            return {};
          }(),
        ));
        return;
      }
    } catch (e) {
      if (onError != null) {
        return onError(e);
      }
    }
  });
}