@bobfrankston/mailx-store 0.1.22 → 0.1.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-store",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/parse-serial.d.ts CHANGED
@@ -27,7 +27,8 @@
27
27
  * pool is built.
28
28
  */
29
29
  import { type ParsedMail, type Source } from "mailparser";
30
- /** Serialized wrapper around `mailparser.simpleParser`. Drop-in replacement —
31
- * same signature, same return value. */
32
- export declare function parseSerial(source: Source): Promise<ParsedMail>;
30
+ /** Serialized wrapper around `mailparser.simpleParser`. `priority` defaults
31
+ * to "foreground" only sync/background callers should pass "background"
32
+ * so user clicks aren't stuck behind a back-fill. */
33
+ export declare function parseSerial(source: Source, priority?: "foreground" | "background"): Promise<ParsedMail>;
33
34
  //# sourceMappingURL=parse-serial.d.ts.map
package/parse-serial.js CHANGED
@@ -27,12 +27,42 @@
27
27
  * pool is built.
28
28
  */
29
29
  import { simpleParser } from "mailparser";
30
- let _chain = Promise.resolve();
31
- /** Serialized wrapper around `mailparser.simpleParser`. Drop-in replacement
32
- * same signature, same return value. */
33
- export async function parseSerial(source) {
34
- const queued = _chain.then(() => simpleParser(source));
35
- _chain = queued.catch(() => undefined);
36
- return queued;
30
+ const _head = []; // UI / foreground — drained first
31
+ const _tail = []; // sync / background
32
+ let _pumping = false;
33
+ async function pump() {
34
+ if (_pumping)
35
+ return;
36
+ _pumping = true;
37
+ try {
38
+ for (;;) {
39
+ const next = _head.shift() ?? _tail.shift();
40
+ if (!next)
41
+ break;
42
+ try {
43
+ const parsed = await simpleParser(next.source);
44
+ next.resolve(parsed);
45
+ }
46
+ catch (e) {
47
+ next.reject(e);
48
+ }
49
+ }
50
+ }
51
+ finally {
52
+ _pumping = false;
53
+ }
54
+ }
55
+ /** Serialized wrapper around `mailparser.simpleParser`. `priority` defaults
56
+ * to "foreground" — only sync/background callers should pass "background"
57
+ * so user clicks aren't stuck behind a back-fill. */
58
+ export async function parseSerial(source, priority = "foreground") {
59
+ return new Promise((resolve, reject) => {
60
+ const entry = { source, resolve, reject };
61
+ if (priority === "foreground")
62
+ _head.push(entry);
63
+ else
64
+ _tail.push(entry);
65
+ pump();
66
+ });
37
67
  }
38
68
  //# sourceMappingURL=parse-serial.js.map