feat: add return value of JavaScriptEntry.subscribe

This commit is contained in:
Frank.R.Wu 2021-11-05 14:13:22 +08:00
parent 47ed2656dd
commit 18f40dc6a9

View File

@ -586,12 +586,13 @@ public class JavaScriptEntry {
* @param fun related handler function * @param fun related handler function
* @author Kaidong Wu * @author Kaidong Wu
*/ */
public static void subscribe(String topic, ScriptFunction fun) { public static String subscribe(String topic, ScriptFunction fun) {
subscribe(topic, fun, false); subscribe(topic, fun, false);
if (topic_handlers.containsKey(topic)) { if (topic_handlers.containsKey(topic)) {
ContractProcess.instance.unSubscribe(topic_handlers.get(topic).getName()); ContractProcess.instance.unSubscribe(topic_handlers.get(topic).getName());
} }
topic_handlers.put(topic, fun); topic_handlers.put(topic, fun);
return topic;
} }
/** /**
@ -602,13 +603,14 @@ public class JavaScriptEntry {
* @param fun related handler function * @param fun related handler function
* @author Kaidong Wu * @author Kaidong Wu
*/ */
public static void subscribe(String contractID, String event, ScriptFunction fun) { public static String subscribe(String contractID, String event, ScriptFunction fun) {
String topic = HashUtil.sha3(contractID, event); String topic = HashUtil.sha3(contractID, event);
subscribe(topic, fun, false); subscribe(topic, fun, false);
if (topic_handlers.containsKey(topic)) { if (topic_handlers.containsKey(topic)) {
ContractProcess.instance.unSubscribe(topic_handlers.get(topic).getName()); ContractProcess.instance.unSubscribe(topic_handlers.get(topic).getName());
} }
topic_handlers.put(topic, fun); topic_handlers.put(topic, fun);
return topic;
} }
private static void subscribe(String topic, ScriptFunction fun, boolean fromPreSub) { private static void subscribe(String topic, ScriptFunction fun, boolean fromPreSub) {