diff --git a/lib/device_flow_handle.js b/lib/device_flow_handle.js index 2c47e179..fb630522 100644 --- a/lib/device_flow_handle.js +++ b/lib/device_flow_handle.js @@ -32,10 +32,16 @@ class DeviceFlowHandle { instance(this).interval = response.interval * 1000 || 5000; } - async poll() { + async poll(shouldCancel) { if (this.expired()) { throw new RPError('the device code %j has expired and the device authorization session has concluded', this.device_code); } + + if (shouldCancel // has value + && {}.toString.call(shouldCancel) === '[object Function]'// is function + && shouldCancel() === true) { + return; + } await new Promise((resolve) => setTimeout(resolve, instance(this).interval));