add subscription recycle

This commit is contained in:
王劲鹏
2021-06-08 10:08:38 +08:00
committed by osborn
parent fa60fd2bc6
commit 59bd3ea1ab
4 changed files with 20 additions and 5 deletions

View File

@@ -53,6 +53,7 @@ void DoricNotificationPlugin::subscribe(QString jsValueString,
args.append(data);
DoricPromise::resolve(getContext(), notificationCallbackId, args);
});
subscriptions.append(subscribeId);
getContext()->getDriver()->asyncCall(
[this, callbackId, notificationCallbackId] {
@@ -68,7 +69,9 @@ void DoricNotificationPlugin::unsubscribe(QString jsValueString,
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
QJsonValue jsValue = document.object();
DoricGlobalBroadcast::getInstance()->unsubscribe(jsValueString);
QString subscribeId = jsValueString;
DoricGlobalBroadcast::getInstance()->unsubscribe(subscribeId);
subscriptions.removeOne(subscribeId);
getContext()->getDriver()->asyncCall(
[this, callbackId] {
@@ -77,3 +80,9 @@ void DoricNotificationPlugin::unsubscribe(QString jsValueString,
},
DoricThreadMode::JS);
}
DoricNotificationPlugin::~DoricNotificationPlugin() {
foreach (QString subscribeId, this->subscriptions) {
DoricGlobalBroadcast::getInstance()->unsubscribe(subscribeId);
}
}