-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With autoUnref set to true (default: false), the Socket.IO client will allow the program to exit if there is no other active timer/socket in the event system. ```js const socket = io({ autoUnref: true }); ``` Note: this option only applies to Node.js clients. Related: #1446
- Loading branch information
1 parent
5902365
commit 6abfa1f
Showing
10 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const io = require("../.."); | ||
const socket = io("http://localhost:3211", { | ||
autoUnref: false, | ||
}); | ||
|
||
setTimeout(() => { | ||
console.log("process should not exit"); | ||
}, 500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const io = require("../.."); | ||
const socket = io("http://localhost:3211", { | ||
autoUnref: true, | ||
}); | ||
|
||
socket.on("open", () => { | ||
console.log("open"); | ||
}); | ||
|
||
setTimeout(() => { | ||
console.log("process should exit now"); | ||
}, 500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const io = require("../.."); | ||
const socket = io("http://localhost:3210", { | ||
autoUnref: true, | ||
transports: ["polling"], | ||
}); | ||
|
||
socket.on("open", () => { | ||
console.log("open"); | ||
}); | ||
|
||
setTimeout(() => { | ||
console.log("process should exit now"); | ||
}, 500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const io = require("../.."); | ||
const socket = io("http://localhost:3210", { | ||
autoUnref: true, | ||
transports: ["websocket"], | ||
}); | ||
|
||
socket.on("open", () => { | ||
console.log("open"); | ||
}); | ||
|
||
setTimeout(() => { | ||
console.log("process should exit now"); | ||
}, 500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const io = require("../.."); | ||
const socket = io("http://localhost:3210", { | ||
autoUnref: true, | ||
}); | ||
|
||
socket.on("open", () => { | ||
console.log("open"); | ||
}); | ||
|
||
setTimeout(() => { | ||
console.log("process should exit now"); | ||
}, 500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const path = require("path"); | ||
const { exec } = require("child_process"); | ||
|
||
describe("autoRef option", () => { | ||
const fixture = (filename) => | ||
process.execPath + " " + path.join(__dirname, "fixtures", filename); | ||
|
||
it("should stop once the timer is triggered", (done) => { | ||
exec(fixture("unref.ts"), done); | ||
}); | ||
|
||
it("should stop once the timer is triggered (even when trying to reconnect)", (done) => { | ||
exec(fixture("unref-during-reconnection.ts"), done); | ||
}); | ||
|
||
it("should stop once the timer is triggered (polling)", (done) => { | ||
exec(fixture("unref-polling-only.ts"), done); | ||
}); | ||
|
||
it("should stop once the timer is triggered (websocket)", (done) => { | ||
exec(fixture("unref-websocket-only.ts"), done); | ||
}); | ||
|
||
it("should not stop with autoUnref set to false", (done) => { | ||
const process = exec(fixture("no-unref.ts"), () => { | ||
done(new Error("should not happen")); | ||
}); | ||
setTimeout(() => { | ||
process.kill(); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); |