From a10a3a8d63d482e481c441569f8b0f215d3a170f Mon Sep 17 00:00:00 2001 From: nanov Date: Wed, 20 Nov 2019 14:40:18 +0200 Subject: [PATCH] feat: async letter serialization --- lib/BankLetter.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/BankLetter.js b/lib/BankLetter.js index 1a98282..eb732ad 100644 --- a/lib/BankLetter.js +++ b/lib/BankLetter.js @@ -24,6 +24,12 @@ const registerHelpers = () => { return digest.toUpperCase().match(/.{1,2}/g).join(' '); }); }; + +const writeFile = (file, content) => new Promise((resolve, reject) => fs.writeFile(file, content, (err, result) => { + if (err) + return reject(err); + return resolve(result); +})); module.exports = class BankLetter { constructor({ client, @@ -55,13 +61,7 @@ module.exports = class BankLetter { async serialize(path) { const letter = await this.generate(); - - try { - fs.writeFileSync(path, letter); - } catch (error) { - throw error; - } - - return new Promise(resolve => resolve(true)); + await writeFile(path, letter); + return true; } };