Skip to content

Commit

Permalink
feat!: use ProtocolSubscription as new base subscription base class
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed May 24, 2024
1 parent c7f7441 commit bc2696c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
14 changes: 6 additions & 8 deletions lib/src/binding_coap/coap_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import "package:coap/coap.dart";

import "../../core.dart";

/// [Subscription] to a CoAP resource, based on the observe option ([RFC 7641]).
/// [ProtocolSubscription] to a CoAP resource, based on the observe option
/// ([RFC 7641]).
///
/// [RFC 7641]: https://datatracker.ietf.org/doc/html/rfc7641
class CoapSubscription implements Subscription {
class CoapSubscription extends ProtocolSubscription {
/// Constructor
CoapSubscription(
this._coapClient,
this._observeClientRelation,
this._complete,
super._complete,
) : _active = true;

final CoapClient _coapClient;
Expand All @@ -28,10 +29,6 @@ class CoapSubscription implements Subscription {
@override
bool get active => _active;

/// Callback used to pass by the servient that is used to signal it that an
/// observation has been cancelled.
final void Function() _complete;

@override
Future<void> stop({
int? formIndex,
Expand All @@ -48,6 +45,7 @@ class CoapSubscription implements Subscription {
await _coapClient.cancelObserveProactive(observeClientRelation);
}
_coapClient.close();
_complete();
await super
.stop(formIndex: formIndex, uriVariables: uriVariables, data: data);
}
}
11 changes: 5 additions & 6 deletions lib/src/binding_mqtt/mqtt_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import "package:mqtt_client/mqtt_server_client.dart";

import "../../core.dart";

/// [Subscription] for the MQTT protocol.
class MqttSubscription implements Subscription {
/// [ProtocolSubscription] for the MQTT protocol.
class MqttSubscription extends ProtocolSubscription {
/// Constructor.
MqttSubscription(
this._form,
this._client,
this._complete, {
super._complete, {
required void Function(Content content) next,
void Function(Exception error)? error,
}) : _active = true {
Expand Down Expand Up @@ -52,8 +52,6 @@ class MqttSubscription implements Subscription {

bool _active = true;

final void Function() _complete;

@override
bool get active => _active;

Expand All @@ -65,6 +63,7 @@ class MqttSubscription implements Subscription {
}) async {
_client.disconnect();
_active = false;
_complete();
await super
.stop(formIndex: formIndex, uriVariables: uriVariables, data: data);
}
}

0 comments on commit bc2696c

Please sign in to comment.