refactor: change settimeout to waitFor (#2220)

This commit is contained in:
Clark Du 2017-11-24 16:09:45 +08:00 committed by Pooya Parsa
parent 65f4a030f4
commit 30714c989a
3 changed files with 7 additions and 13 deletions

View File

@ -9,7 +9,7 @@ import { join, resolve, basename, extname, dirname } from 'path'
import MFS from 'memory-fs'
import webpackDevMiddleware from 'webpack-dev-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 Glob from 'glob'
import clientWebpackConfig from './webpack/client.config.js'
@ -132,11 +132,8 @@ export default class Builder {
// If building
/* istanbul ignore if */
if (this._buildStatus === STATUS.BUILDING) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(this.build())
}, 1000)
})
await waitFor(1000)
return this.build()
}
this._buildStatus = STATUS.BUILDING

View File

@ -23,9 +23,7 @@ export function setAnsiColors(ansiHTML) {
}
export async function waitFor(ms) {
return new Promise(function (resolve) {
setTimeout(resolve, (ms || 0))
})
return new Promise(resolve => setTimeout(resolve, (ms || 0)))
}
export function urlJoin() {

View File

@ -8,7 +8,7 @@ import _ from 'lodash'
import { join, resolve } from 'path'
import fs from 'fs-extra'
import { createBundleRenderer } from 'vue-server-renderer'
import { getContext, setAnsiColors, isUrl } from 'utils'
import { getContext, setAnsiColors, isUrl, waitFor } from 'utils'
import Debug from 'debug'
import Youch from '@nuxtjs/youch'
import { SourceMapConsumer } from 'source-map'
@ -472,9 +472,8 @@ export default class Renderer {
async renderRoute(url, context = {}) {
/* istanbul ignore if */
if (!this.isReady) {
return new Promise(resolve => {
setTimeout(() => resolve(this.renderRoute(url, context)), 1000)
})
await waitFor(1000)
return this.renderRoute(url, context)
}
// Log rendered url