Skip to content

Commit 6486fff

Browse files
committed
Make pubsub.sub return Map
1 parent 31be2cf commit 6486fff

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/main/java/io/ipfs/api/IPFS.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,13 @@ public Object pub(String topic, String data) throws IOException {
246246
return retrieveAndParse("pubsub/pub?arg="+topic + "&arg=" + data);
247247
}
248248

249-
public Supplier<Object> sub(String topic) throws IOException {
249+
public Supplier<Map<String, Object>> sub(String topic) throws IOException {
250250
return sub(topic, ForkJoinPool.commonPool());
251251
}
252252

253-
public Supplier<Object> sub(String topic, ForkJoinPool threadSupplier) throws IOException {
254-
return retrieveAndParseStream("pubsub/sub?arg="+topic, threadSupplier);
253+
public Supplier<Map<String, Object>> sub(String topic, ForkJoinPool threadSupplier) throws IOException {
254+
Supplier<Object> sup = retrieveAndParseStream("pubsub/sub?arg=" + topic, threadSupplier);
255+
return () -> (Map) sup.get();
255256
}
256257

257258
/**
@@ -260,8 +261,8 @@ public Supplier<Object> sub(String topic, ForkJoinPool threadSupplier) throws IO
260261
* @param results
261262
* @throws IOException
262263
*/
263-
public void sub(String topic, Consumer<Object> results) throws IOException {
264-
retrieveAndParseStream("pubsub/sub?arg="+topic, results);
264+
public void sub(String topic, Consumer<Map<String, Object>> results) throws IOException {
265+
retrieveAndParseStream("pubsub/sub?arg="+topic, res -> results.accept((Map)res));
265266
}
266267

267268

src/test/java/io/ipfs/api/APITest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void bulkBlockTest() throws IOException {
383383
@Test
384384
public void pubsubSynchronous() throws IOException {
385385
String topic = "topic" + System.nanoTime();
386-
List<Object> res = Collections.synchronizedList(new ArrayList<>());
386+
List<Map<String, Object>> res = Collections.synchronizedList(new ArrayList<>());
387387
new Thread(() -> {
388388
try {
389389
ipfs.pubsub.sub(topic, res::add);
@@ -410,12 +410,12 @@ public void pubsub() throws IOException {
410410
Object ls = ipfs.pubsub.ls();
411411
Object peers = ipfs.pubsub.peers();
412412
String topic = "topic" + System.nanoTime();
413-
Supplier<Object> sub = ipfs.pubsub.sub(topic);
414-
Object first = sub.get();
413+
Supplier<Map<String, Object>> sub = ipfs.pubsub.sub(topic);
414+
Map<String, Object> first = sub.get();
415415
Assert.assertTrue(first.equals(Collections.emptyMap()));
416416
String data = "Hello!";
417417
Object pub = ipfs.pubsub.pub(topic, data);
418-
Object second = sub.get();
418+
Map second = sub.get();
419419
Assert.assertTrue( ! second.equals(Collections.emptyMap()));
420420
}
421421

0 commit comments

Comments
 (0)