Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Closeable on Browser and Page to use try-resource syntax #116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/com/ruiyun/jvppeteer/core/browser/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ruiyun.jvppeteer.util.StringUtil;
import com.ruiyun.jvppeteer.util.ValidateUtil;

import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -33,7 +34,7 @@
/**
* 浏览器实例
*/
public class Browser extends EventEmitter {
public class Browser extends EventEmitter implements Closeable {

/**
* 浏览器对应的websocket client包装类,用于发送和接受消息
Expand Down Expand Up @@ -298,6 +299,7 @@ public String userAgent() {
return version.get("userAgent").asText();
}

@Override
public void close() {
this.closeCallback.apply(null);
this.disconnect();
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/ruiyun/jvppeteer/core/page/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.ProtocolException;
Expand Down Expand Up @@ -95,7 +96,7 @@
import static com.ruiyun.jvppeteer.core.Constant.RECV_MESSAGE_STREAM_PROPERTY;
import static com.ruiyun.jvppeteer.core.Constant.supportedMetrics;

public class Page extends EventEmitter {
public class Page extends EventEmitter implements Closeable {

private static final ExecutorService reloadExecutor = Executors.newSingleThreadExecutor();

Expand Down Expand Up @@ -709,8 +710,13 @@ public void click(String selector, ClickOptions options,boolean isBlock) throws
* 关闭页面
* @throws InterruptedException 异常
*/
public void close() throws InterruptedException {
this.close(false);
@Override
public void close() {
try {
this.close(false);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

/**
Expand Down