mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
refactor: change settimeout to waitFor (#2220)
This commit is contained in:
parent
65f4a030f4
commit
30714c989a
@ -9,7 +9,7 @@ import { join, resolve, basename, extname, dirname } from 'path'
|
|||||||
import MFS from 'memory-fs'
|
import MFS from 'memory-fs'
|
||||||
import webpackDevMiddleware from 'webpack-dev-middleware'
|
import webpackDevMiddleware from 'webpack-dev-middleware'
|
||||||
import webpackHotMiddleware from 'webpack-hot-middleware'
|
import webpackHotMiddleware from 'webpack-hot-middleware'
|
||||||
import { r, wp, wChunk, createRoutes, sequence, relativeTo, isPureObject } from 'utils'
|
import { r, wp, wChunk, createRoutes, sequence, relativeTo, isPureObject, waitFor } from 'utils'
|
||||||
import Debug from 'debug'
|
import Debug from 'debug'
|
||||||
import Glob from 'glob'
|
import Glob from 'glob'
|
||||||
import clientWebpackConfig from './webpack/client.config.js'
|
import clientWebpackConfig from './webpack/client.config.js'
|
||||||
@ -132,11 +132,8 @@ export default class Builder {
|
|||||||
// If building
|
// If building
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (this._buildStatus === STATUS.BUILDING) {
|
if (this._buildStatus === STATUS.BUILDING) {
|
||||||
return new Promise((resolve) => {
|
await waitFor(1000)
|
||||||
setTimeout(() => {
|
return this.build()
|
||||||
resolve(this.build())
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
this._buildStatus = STATUS.BUILDING
|
this._buildStatus = STATUS.BUILDING
|
||||||
|
|
||||||
|
@ -23,9 +23,7 @@ export function setAnsiColors(ansiHTML) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function waitFor(ms) {
|
export async function waitFor(ms) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(resolve => setTimeout(resolve, (ms || 0)))
|
||||||
setTimeout(resolve, (ms || 0))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function urlJoin() {
|
export function urlJoin() {
|
||||||
|
@ -8,7 +8,7 @@ import _ from 'lodash'
|
|||||||
import { join, resolve } from 'path'
|
import { join, resolve } from 'path'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import { createBundleRenderer } from 'vue-server-renderer'
|
import { createBundleRenderer } from 'vue-server-renderer'
|
||||||
import { getContext, setAnsiColors, isUrl } from 'utils'
|
import { getContext, setAnsiColors, isUrl, waitFor } from 'utils'
|
||||||
import Debug from 'debug'
|
import Debug from 'debug'
|
||||||
import Youch from '@nuxtjs/youch'
|
import Youch from '@nuxtjs/youch'
|
||||||
import { SourceMapConsumer } from 'source-map'
|
import { SourceMapConsumer } from 'source-map'
|
||||||
@ -472,9 +472,8 @@ export default class Renderer {
|
|||||||
async renderRoute(url, context = {}) {
|
async renderRoute(url, context = {}) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!this.isReady) {
|
if (!this.isReady) {
|
||||||
return new Promise(resolve => {
|
await waitFor(1000)
|
||||||
setTimeout(() => resolve(this.renderRoute(url, context)), 1000)
|
return this.renderRoute(url, context)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log rendered url
|
// Log rendered url
|
||||||
|
Loading…
Reference in New Issue
Block a user