-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Usage: ```js socket.timeout(5000).emit("my-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); ```
- Loading branch information
1 parent
b7213e7
commit f0ed42f
Showing
4 changed files
with
107 additions
and
4 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
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,34 @@ | ||
import { Server } from ".."; | ||
import { createClient, success } from "./support/util"; | ||
import expect from "expect.js"; | ||
|
||
describe("timeout", () => { | ||
it("should timeout if the client does not acknowledge the event", (done) => { | ||
const io = new Server(0); | ||
const client = createClient(io, "/"); | ||
|
||
io.on("connection", (socket) => { | ||
socket.timeout(50).emit("unknown", (err) => { | ||
expect(err).to.be.an(Error); | ||
success(done, io, client); | ||
}); | ||
}); | ||
}); | ||
|
||
it("should not timeout if the client does acknowledge the event", (done) => { | ||
const io = new Server(0); | ||
const client = createClient(io, "/"); | ||
|
||
client.on("echo", (arg, cb) => { | ||
cb(arg); | ||
}); | ||
|
||
io.on("connection", (socket) => { | ||
socket.timeout(50).emit("echo", 42, (err, value) => { | ||
expect(err).to.be(null); | ||
expect(value).to.be(42); | ||
success(done, io, client); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -2888,4 +2888,6 @@ describe("socket.io", () => { | |
}); | ||
}); | ||
}); | ||
|
||
require("./socket-timeout"); | ||
}); |
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