From f4f015a6219fc8efdb521dad72fb860361235de8 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Fri, 25 Aug 2017 18:51:51 +0300 Subject: [PATCH] src/telegram: Use $NTBA_FIX_319 to apply fix for #319 Notes: The permanent fix introduces backwards-incompatible changes, which require a major version bump. Until we release v1, environment variable `${NTBA_FIX_319}` can be used to apply the fix. References: * BR: https://github.com/yagop/node-telegram-bot-api/issues/319 --- src/telegram.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/telegram.js b/src/telegram.js index 70e1fcd..ffedbfa 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -50,24 +50,26 @@ const _deprecatedMessageTypes = [ ]; -// Enable Promise cancellation. -try { - const msg = - 'Automatic enabling of cancellation of promises is deprecated.\n' + - 'In the future, you will have to enable it yourself.\n' + - 'See https://github.com/yagop/node-telegram-bot-api/issues/319.'; - deprecate(msg); - Promise.config({ - cancellation: true, - }); -} catch (ex) { - /* eslint-disable no-console */ - const msg = - 'error: Enabling Promise cancellation failed.\n' + - ' Temporary fix is to load/require this library as early as possible before using any Promises.'; - console.error(msg); - throw ex; - /* eslint-enable no-console */ +if (!process.env.NTBA_FIX_319) { + // Enable Promise cancellation. + try { + const msg = + 'Automatic enabling of cancellation of promises is deprecated.\n' + + 'In the future, you will have to enable it yourself.\n' + + 'See https://github.com/yagop/node-telegram-bot-api/issues/319.'; + deprecate(msg); + Promise.config({ + cancellation: true, + }); + } catch (ex) { + /* eslint-disable no-console */ + const msg = + 'error: Enabling Promise cancellation failed.\n' + + ' Temporary fix is to load/require this library as early as possible before using any Promises.'; + console.error(msg); + throw ex; + /* eslint-enable no-console */ + } }