Skip to content

Commit ed3ef43

Browse files
MytsVmaany
authored andcommitted
Produce an error when streaming doesn't yield any results
1 parent 8a1f0e7 commit ed3ef43

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

public/streamWorker.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
self.onmessage = async function (event) {
22
const {url, fetchOptions, updateDelay = 50, maxUpdateLength = 100} = event.data;
33
const buffer = [];
4+
let foundEntries = false;
45

56
const postData = () => {
7+
foundEntries = true;
68
// Remove the first {maxUpdateLength} or all elements from the buffer
79
const dataToSend = buffer.length > maxUpdateLength ? buffer.splice(0, maxUpdateLength) : buffer.splice(0);
810
self.postMessage({type: 'data', data: dataToSend});
@@ -17,7 +19,11 @@ self.onmessage = async function (event) {
1719
const finalize = () => {
1820
handleUpdate();
1921
if (buffer.length === 0) {
20-
self.postMessage({type: 'finish'});
22+
if (foundEntries) {
23+
self.postMessage({type: 'finish'});
24+
} else {
25+
handleError('not_found', 'No entries found.');
26+
}
2127
}
2228
};
2329

0 commit comments

Comments
 (0)