@yarkivaev/source-to-sink 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/batch.js +11 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/source-to-sink",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Generic library for building data streaming pipelines",
5
5
  "repository": {
6
6
  "type": "git",
package/src/batch.js CHANGED
@@ -38,12 +38,20 @@ export default function batch(sink, size, circuit) {
38
38
  return;
39
39
  }
40
40
  const pending = records;
41
+ records = [];
41
42
  try {
42
- sink.write(pending);
43
- records = [];
44
- circuit.succeed();
43
+ const result = sink.write(pending);
44
+ if (result && typeof result.then === 'function') {
45
+ result.then(
46
+ () => { circuit.succeed(); },
47
+ () => { circuit.fail(); records = pending.concat(records); }
48
+ );
49
+ } else {
50
+ circuit.succeed();
51
+ }
45
52
  } catch (err) {
46
53
  circuit.fail();
54
+ records = pending.concat(records);
47
55
  throw err;
48
56
  }
49
57
  }