Commit 0c9827a
committed
stream: fix Writer sync method return values for try-fallback pattern
All `*Sync` methods on the Writer interface are designed as
try-fallback pairs with their async counterparts: attempt the
fast synchronous path first, and fall back to the async version
only when the synchronous call indicates it could not complete.
`endSync()` was returning the byte count unconditionally, making
the fallback check in duplex `close()` incorrect (`!0 === true`).
`failSync()` always returned true even when already errored.
- `endSync()` now returns -1 when writer is not open, byte count
(`>= 0`) on success
- `failSync()` now returns false when already errored
- `PushQueue.fail()` returns boolean to support `failSync()`
- duplex `close()` uses `endSync() < 0` for the fallback check
- Document the try-fallback pattern and sync return values1 parent a6a37e5 commit 0c9827a
4 files changed
Lines changed: 40 additions & 8 deletions
File tree
- doc/api
- lib/internal/streams/iter
- test/parallel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
698 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
699 | 711 | | |
700 | 712 | | |
701 | 713 | | |
| |||
707 | 719 | | |
708 | 720 | | |
709 | 721 | | |
| 722 | + | |
| 723 | + | |
710 | 724 | | |
711 | | - | |
| 725 | + | |
712 | 726 | | |
713 | 727 | | |
714 | 728 | | |
| |||
726 | 740 | | |
727 | 741 | | |
728 | 742 | | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
729 | 757 | | |
730 | 758 | | |
731 | 759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
264 | 265 | | |
265 | 266 | | |
266 | | - | |
| 267 | + | |
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
| 275 | + | |
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
| |||
512 | 514 | | |
513 | 515 | | |
514 | 516 | | |
515 | | - | |
516 | | - | |
| 517 | + | |
517 | 518 | | |
518 | 519 | | |
519 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
111 | 114 | | |
112 | 115 | | |
113 | 116 | | |
| |||
0 commit comments