Skip to content

Commit

Permalink
Wait upto 30 seconds for server ready
Browse files Browse the repository at this point in the history
Resolves sveltejs#730
  • Loading branch information
thgh committed Nov 9, 2019
1 parent b1c4585 commit d26569c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ class Watcher extends EventEmitter {
deferred.promise.then(() => {
const restart = () => {
this.crashed = false;
this.restarted_at = this.restarted_at || Date.now()

ports.wait(this.port)
.then((() => {
this.restarted_at = 0
this.emit('ready', <ReadyEvent>{
port: this.port,
process: this.proc
Expand All @@ -266,9 +268,14 @@ class Watcher extends EventEmitter {
.catch(err => {
if (this.crashed) return;

const delay = Math.round((Date.now() - this.restarted_at) / 1000)
this.emit('fatal', <FatalEvent>{
message: `Server is not listening on port ${this.port}`
message: `Server is not listening on port ${this.port} after ${delay} seconds`
});

if (delay < 30) {
restart()
}
});
};

Expand Down

0 comments on commit d26569c

Please sign in to comment.