function drain(timeout) {
        return new SyncPromise(function (resolve, reject) {
            var counter = buffer.length;
            if (!counter) {
                return resolve(true);
            }
            // wait for `timeout` ms and then resolve to `false` (if not cancelled first)
            var capturedSetTimeout = setTimeout(function () {
                if (timeout && timeout > 0) {
                    resolve(false);
                }
            }, timeout);
            // if all promises resolve in time, cancel the timer and resolve to `true`
            buffer.forEach(function (item) {
                void resolvedSyncPromise(item).then(function () {
                    // eslint-disable-next-line no-plusplus
                    if (!--counter) {
                        clearTimeout(capturedSetTimeout);
                        resolve(true);
                    }
                }, reject);
            });
        });
    }
Wait for all promises in the queue to resolve or for timeout to expire, whichever comes first.

@param timeout The time, in ms, after which to resolve to `false` if the queue is still non-empty. Passing `0` (or
not passing anything) will make the promise wait as long as it takes for the queue to drain before resolving to
`true`.
@returns A promise which will resolve to `true` if the queue is already empty or drains before the timeout, and
`false` otherwise