Merged
This commit is contained in:
1 parent
29460fabf6
commit
a4e21f67f6
20 files changed
+172
-77
No files matched your search
@@ -86,16 +86,38 @@ namespace bts.api.core {
|
||||
};
|
||||
var subscription = ApiNativeMethods.api_client_subscribe(_client, method_and_qualifier, cb, IntPtr.Zero);
|
||||
_subscriptions.Add(subscription);
|
||||
return Disposable.Create(() => {
|
||||
return FinalizeableAnonymousDisposable.Create((disposing) => {
|
||||
ApiNativeMethods.api_client_unsubscribe(_client, subscription);
|
||||
_subscriptions.Remove(subscription);
|
||||
// keepalive
|
||||
cb = null;
|
||||
if (!disposing) {
|
||||
observer.OnError(new ObjectDisposedException("Subscription has been terminated because the returned IDisposable has been finalized."));
|
||||
}
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
private class FinalizeableAnonymousDisposable : IDisposable {
|
||||
private Action<bool> _action;
|
||||
public FinalizeableAnonymousDisposable(Action<bool> dispose) {
|
||||
_action = dispose;
|
||||
}
|
||||
public static FinalizeableAnonymousDisposable Create(Action<bool> dispose) { return new FinalizeableAnonymousDisposable(dispose); }
|
||||
~FinalizeableAnonymousDisposable() {
|
||||
Dispose(false);
|
||||
}
|
||||
public void Dispose() {
|
||||
GC.SuppressFinalize(this);
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
_action?.Invoke(disposing);
|
||||
_action = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool is_sync_call_ok() {
|
||||
return !ApiNativeMethods.api_client_is_on_qb_thread(_client);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user