Skip to content

Commit 1ceb6b9

Browse files
author
Fletcher91
committed
[FIX] Issue where requestMap entries were deleted before they'd finish
1 parent 01abfee commit 1ceb6b9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/processor/DataProcessor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class DataProcessor {
153153
private _fetcher: Fetcher | undefined;
154154
private readonly requestInitGenerator: RequestInitGenerator;
155155
private readonly mapping: { [k: string]: ResponseTransformer[] };
156-
private readonly requestMap: { [k: string]: Promise<Statement[]> | undefined };
156+
private readonly requestMap: Map<NamedNode, Promise<Statement[]> | undefined>;
157157
private readonly requestNotifier?: RequestCallbackHandler;
158158
private readonly store: RDFStore;
159159

@@ -182,7 +182,7 @@ export class DataProcessor {
182182
};
183183
this.requestInitGenerator = opts.requestInitGenerator || new RequestInitGenerator();
184184
this.mapping = opts.mapping || {};
185-
this.requestMap = {};
185+
this.requestMap = new Map();
186186
this.store = opts.store;
187187
this.requestNotifier = opts.requestNotifier;
188188
if (opts.fetcher) {
@@ -290,14 +290,16 @@ export class DataProcessor {
290290
const url = new URL(iri.value);
291291
url.hash = "";
292292
const requestIRI = new NamedNode(url.toString());
293-
if (typeof this.requestMap[requestIRI.toString()] !== "undefined") {
294-
return this.requestMap[requestIRI.toString()] || [];
293+
if (this.requestMap.has(requestIRI)) {
294+
return this.requestMap.get(requestIRI) || [];
295295
}
296296

297297
try {
298-
return this.requestMap[requestIRI.toString()] = this
298+
const req = this
299299
.fetchResource(requestIRI, opts)
300300
.then((res) => this.feedResponse(res)); // TODO: feedResponse is only necessary for external requests.
301+
this.requestMap.set(requestIRI, req);
302+
return await req;
301303
} catch (e) {
302304
if (typeof e.res === "undefined") {
303305
throw e;
@@ -307,7 +309,7 @@ export class DataProcessor {
307309

308310
return responseQuads;
309311
} finally {
310-
this.requestMap[requestIRI.toString()] = undefined;
312+
this.requestMap.delete(requestIRI);
311313
}
312314
}
313315

0 commit comments

Comments
 (0)