Now destroying client when no torrent is left to download or handle

This commit is contained in:
Kylart 2021-01-06 03:28:06 +01:00
parent 6db5b5e47e
commit 08a6c4ea0d
3 changed files with 8 additions and 14 deletions

View File

@ -24,8 +24,7 @@ Napi::Object Client::Init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass( Napi::Function func = DefineClass(
env, env,
"Client", "Client",
{InstanceMethod("destroy", &Client::Destroy), {InstanceMethod("addTorrent", &Client::AddTorrent),
InstanceMethod("addTorrent", &Client::AddTorrent),
InstanceMethod("getTorrents", &Client::GetTorrents), InstanceMethod("getTorrents", &Client::GetTorrents),
InstanceMethod("getTorrent", &Client::GetTorrent), InstanceMethod("getTorrent", &Client::GetTorrent),
InstanceMethod("removeTorrent", &Client::RemoveTorrent), InstanceMethod("removeTorrent", &Client::RemoveTorrent),
@ -45,16 +44,6 @@ Client::Client(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Client>(info)
Napi::HandleScope scope(env); Napi::HandleScope scope(env);
} }
Napi::Value Client::Destroy(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
this->session_proxy = this->session.abort();
this->session.~session();
this->session_proxy.~session_proxy();
return Napi::Boolean::New(env, true);
}
Napi::Value Client::GetTorrents(const Napi::CallbackInfo& info) { Napi::Value Client::GetTorrents(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env(); Napi::Env env = info.Env();
Napi::Array result = Napi::Array::New(env); Napi::Array result = Napi::Array::New(env);

View File

@ -49,7 +49,6 @@ class Client : public Napi::ObjectWrap<Client> {
lt::session session; lt::session session;
lt::session_proxy session_proxy; lt::session_proxy session_proxy;
Napi::Value Destroy(const Napi::CallbackInfo& info);
Napi::Value AddTorrent(const Napi::CallbackInfo& info); Napi::Value AddTorrent(const Napi::CallbackInfo& info);
Napi::Value RemoveTorrent(const Napi::CallbackInfo& info); Napi::Value RemoveTorrent(const Napi::CallbackInfo& info);
Napi::Value GetTorrents(const Napi::CallbackInfo &info); Napi::Value GetTorrents(const Napi::CallbackInfo &info);

View File

@ -30,7 +30,13 @@ function initInfoInterval () {
sendToWindows(events.info.success, info()) sendToWindows(events.info.success, info())
if (!client.getTorrents().length) stopInfoInterval() if (!client.getTorrents().length) {
stopInfoInterval()
// Destroying client, kinda
logger.info('No torrent left in client. Destroying client.')
client = null
}
}, 1000) }, 1000)
} }
} }