|
|
@@ -1,6 +1,23 @@
|
|
|
/* @flow */
|
|
|
|
|
|
const MAX_STACK_DEPTH = 1000
|
|
|
+const noop = _ => _
|
|
|
+
|
|
|
+const defer = typeof process !== 'undefined' && process.nextTick
|
|
|
+ ? process.nextTick
|
|
|
+ : typeof Promise !== 'undefined'
|
|
|
+ ? fn => Promise.resolve().then(fn)
|
|
|
+ : typeof setTimeout !== 'undefined'
|
|
|
+ ? setTimeout
|
|
|
+ : noop
|
|
|
+
|
|
|
+if (defer === noop) {
|
|
|
+ throw new Error(
|
|
|
+ 'Your JavaScript runtime does not support any asynchronous primitives ' +
|
|
|
+ 'that are required by vue-server-renderer. Please use a polyfill for ' +
|
|
|
+ 'either Promise or setTimeout.'
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
export function createWriteFunction (
|
|
|
write: (text: string, next: Function) => boolean,
|
|
|
@@ -14,7 +31,7 @@ export function createWriteFunction (
|
|
|
const waitForNext = write(text, next)
|
|
|
if (waitForNext !== true) {
|
|
|
if (stackDepth >= MAX_STACK_DEPTH) {
|
|
|
- process.nextTick(() => {
|
|
|
+ defer(() => {
|
|
|
try { next() } catch (e) {
|
|
|
onError(e)
|
|
|
}
|