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 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

View File

@ -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() {

View File

@ -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