-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This feature allows to send a packet and expect an acknowledgement from the server within the given delay. Syntax: ```java socket.emit("hello", "world", new AckWithTimeout(5000) { @OverRide public void onTimeout() { // ... } @OverRide public void onSuccess(Object... args) { // ... } }); ``` Related: - #309 - #517
- Loading branch information
1 parent
7375763
commit fca3b95
Showing
3 changed files
with
179 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.socket.client; | ||
|
||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
public abstract class AckWithTimeout implements Ack { | ||
private final long timeout; | ||
private final Timer timer = new Timer(); | ||
|
||
/** | ||
* | ||
* @param timeout delay in milliseconds | ||
*/ | ||
public AckWithTimeout(long timeout) { | ||
this.timeout = timeout; | ||
} | ||
|
||
@Override | ||
public final void call(Object... args) { | ||
this.timer.cancel(); | ||
this.onSuccess(args); | ||
} | ||
|
||
public final void schedule(TimerTask task) { | ||
this.timer.schedule(task, this.timeout); | ||
} | ||
|
||
public final void cancelTimer() { | ||
this.timer.cancel(); | ||
} | ||
|
||
public abstract void onSuccess(Object... args); | ||
public abstract void onTimeout(); | ||
|
||
} |
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