Skip to content

Commit 666716b

Browse files
committed
Should only dispath new future requests
Introduce quick fix that allows dispath method to be called multiple times during the execution of a graphql query. Issue #6
1 parent b5a15ed commit 666716b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ apply from: "$projectDir/gradle/coverage.gradle"
2727
apply from: "$projectDir/gradle/publishing.gradle"
2828

2929
repositories {
30+
mavenLocal()
3031
mavenCentral()
3132
jcenter()
3233
maven {
@@ -35,7 +36,7 @@ repositories {
3536
}
3637

3738
group = 'io.engagingspaces'
38-
version = '0.9.3'
39+
version = '0.9.4'
3940

4041
task docProcessing(type: JavaCompile, group: 'build') {
4142
source = sourceSets.main.java

src/main/java/io/engagingspaces/vertx/dataloader/DataLoader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class DataLoader<K, V> {
5252
private final DataLoaderOptions loaderOptions;
5353
private final CacheMap<Object, Future<V>> futureCache;
5454
private final LinkedHashMap<K, Future<V>> loaderQueue;
55+
private final LinkedHashMap<CompositeFuture, LinkedHashMap<K, Future<V>>> dispatchedQueues;
5556

5657
/**
5758
* Creates a new data loader with the provided batch load function, and default options.
@@ -75,6 +76,7 @@ public DataLoader(BatchLoader<K> batchLoadFunction, DataLoaderOptions options) {
7576
this.loaderOptions = options == null ? new DataLoaderOptions() : options;
7677
this.futureCache = loaderOptions.cacheMap().isPresent() ? (CacheMap<Object, Future<V>>) loaderOptions.cacheMap().get() : CacheMap.simpleMap();
7778
this.loaderQueue = new LinkedHashMap<>();
79+
this.dispatchedQueues = new LinkedHashMap<>();
7880
}
7981

8082
/**
@@ -138,18 +140,20 @@ public CompositeFuture dispatch() {
138140
return CompositeFuture.join(Collections.emptyList());
139141
}
140142
CompositeFuture batch = batchLoadFunction.load(loaderQueue.keySet());
143+
dispatchedQueues.put(batch, new LinkedHashMap<>(loaderQueue));
141144
batch.setHandler(rh -> {
142145
AtomicInteger index = new AtomicInteger(0);
143-
loaderQueue.forEach((key, future) -> {
146+
dispatchedQueues.get(batch).forEach((key, future) -> {
144147
if (batch.succeeded(index.get())) {
145148
future.complete(batch.resultAt(index.get()));
146149
} else {
147150
future.fail(batch.cause(index.get()));
148151
}
149152
index.incrementAndGet();
150153
});
151-
loaderQueue.clear();
154+
dispatchedQueues.remove(batch);
152155
});
156+
loaderQueue.clear();
153157
return batch;
154158
}
155159

0 commit comments

Comments
 (0)