From 40f8a4ddc417b4f0dd99f10373eeb7240ea8cd18 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sun, 12 Oct 2014 02:20:30 +0200 Subject: [PATCH] Delay save function --- src/client.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 48a9464..657fa4f 100644 --- a/src/client.js +++ b/src/client.js @@ -320,7 +320,18 @@ Client.prototype.quit = function() { }); }; -Client.prototype.save = function() { +var timer; +Client.prototype.save = function(force) { + var client = this; + + if (!force) { + clearTimeout(timer); + timer = setTimeout(function() { + client.save(true); + }, 1000); + return; + } + var name = this.name; var path = Helper.HOME + "/users/" + name + "/user.json"; @@ -343,6 +354,7 @@ Client.prototype.save = function() { json.networks = networks; } catch(e) { console.log(e); + return; } fs.writeFile(