mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-01 12:53:31 -05:00
Merge pull request #19830 from overleaf/ae-iterator-polyfill
Always use ReadableStream asyncIterator polyfill GitOrigin-RevId: 660a7316a549fe4ce4fc6bd1ef1a7d7e58759f14
This commit is contained in:
parent
6290718b7e
commit
a71e61791c
2 changed files with 45 additions and 0 deletions
|
@ -3,6 +3,7 @@ import BibLogParser from '../../../ide/log-parser/bib-log-parser'
|
||||||
import { enablePdfCaching } from './pdf-caching-flags'
|
import { enablePdfCaching } from './pdf-caching-flags'
|
||||||
import { debugConsole } from '@/utils/debugging'
|
import { debugConsole } from '@/utils/debugging'
|
||||||
import { dirname, findEntityByPath } from '@/features/file-tree/util/path'
|
import { dirname, findEntityByPath } from '@/features/file-tree/util/path'
|
||||||
|
import '@/utils/readable-stream-async-iterator-polyfill'
|
||||||
|
|
||||||
// Warnings that may disappear after a second LaTeX pass
|
// Warnings that may disappear after a second LaTeX pass
|
||||||
const TRANSIENT_WARNING_REGEX = /^(Reference|Citation).+undefined on input line/
|
const TRANSIENT_WARNING_REGEX = /^(Reference|Citation).+undefined on input line/
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
// @ts-nocheck
|
||||||
|
/**
|
||||||
|
* A polyfill for `ReadableStream.protototype[Symbol.asyncIterator]`,
|
||||||
|
* aligning as closely as possible to the specification.
|
||||||
|
*
|
||||||
|
* from https://gist.github.com/MattiasBuelens/496fc1d37adb50a733edd43853f2f60e
|
||||||
|
*
|
||||||
|
* @see https://streams.spec.whatwg.org/#rs-asynciterator
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#async_iteration
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReadableStream.prototype.values ??= function ({ preventCancel = false } = {}) {
|
||||||
|
const reader = this.getReader()
|
||||||
|
return {
|
||||||
|
async next() {
|
||||||
|
try {
|
||||||
|
const result = await reader.read()
|
||||||
|
if (result.done) {
|
||||||
|
reader.releaseLock()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
} catch (e) {
|
||||||
|
reader.releaseLock()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async return(value) {
|
||||||
|
if (!preventCancel) {
|
||||||
|
const cancelPromise = reader.cancel(value)
|
||||||
|
reader.releaseLock()
|
||||||
|
await cancelPromise
|
||||||
|
} else {
|
||||||
|
reader.releaseLock()
|
||||||
|
}
|
||||||
|
return { done: true, value }
|
||||||
|
},
|
||||||
|
[Symbol.asyncIterator]() {
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReadableStream.prototype[Symbol.asyncIterator] ??=
|
||||||
|
ReadableStream.prototype.values
|
Loading…
Reference in a new issue