You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**(alias for `abortable.source(source, signal, [options])`)**
61
73
62
74
Make any iterator or iterable abortable via an `AbortSignal`.
63
75
64
76
#### Parameters
65
77
66
78
| Name | Type | Description |
67
79
|------|------|-------------|
68
-
|iterator|[`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)\|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| The iterator or iterable object to make abortable |
80
+
|source|[`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)\|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| The iterator or iterable object to make abortable |
69
81
| signal |[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)| Signal obtained from `AbortController.signal` which is used to abort the iterator. |
70
82
| options |`Object`| (optional) options |
71
83
| options.onAbort |`Function`| An (async) function called when the iterator is being aborted, before the abort error is thrown. Default `null`|
72
84
| options.abortMessage |`String`| The message that the error will have if the iterator is aborted. Default "The operation was aborted" |
73
85
| options.abortCode |`String`\|`Number`| The value assigned to the `code` property of the error that is thrown if the iterator is aborted. Default "ABORT_ERR" |
86
+
| options.returnOnAbort |`Boolean`| Instead of throwing the abort error, just return from iterating over the source stream. |
74
87
75
88
#### Returns
76
89
77
90
| Type | Description |
78
91
|------|-------------|
79
-
|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| An iterator that wraps the passed `iterator` parameter that makes it abortable via the passed `signal` parameter. |
92
+
|[`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| An iterator that wraps the passed `source` parameter that makes it abortable via the passed `signal` parameter. |
80
93
81
94
The returned iterator will `throw` an `AbortError` when it is aborted that has a `type` with the value `aborted` and `code` property with the value `ABORT_ERR` by default.
82
95
83
-
### `abortable.multi(iterator, signals)`
96
+
### `abortable(source, signals)`
97
+
**(alias for `abortable.source(source, signals)`)**
84
98
85
99
Make any iterator or iterable abortable via any one of the passed `AbortSignal`'s.
86
100
87
101
#### Parameters
88
102
89
103
| Name | Type | Description |
90
104
|------|------|-------------|
91
-
|iterator|[`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)\|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| The iterator or iterable object to make abortable |
105
+
|source|[`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)\|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| The iterator or iterable object to make abortable |
92
106
| signals |`Array<{ signal, [options] }>`| An array of objects with `signal` and optional `options` properties. See above docs for expected values for these two properties. |
93
107
94
108
#### Returns
95
109
96
110
| Type | Description |
97
111
|------|-------------|
98
-
|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| An iterator that wraps the passed `iterator` parameter that makes it abortable via the passed `signal` parameters. |
112
+
|[`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)| An iterator that wraps the passed `source` parameter that makes it abortable via the passed `signal` parameters. |
99
113
100
114
The returned iterator will `throw` an `AbortError` when it is aborted on _any_ one of the passed abort signals. The error object has a `type` with the value `aborted` and `code` property with the value `ABORT_ERR` by default.
101
115
116
+
### `abortable.sink(sink, signal, [options])`
117
+
118
+
The same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`sink`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it) abortable. Returns a new sink that wraps the passed `sink` and makes it abortable via the passed `signal` parameter.
119
+
120
+
### `abortable.sink(sink, signals)`
121
+
122
+
The same as [`abortable.source`](#abortablesource-signals) except this makes the passed [`sink`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it) abortable via any one of the passed `AbortSignal`'s. Returns a new sink that wraps the passed `sink` and makes it abortable via the passed `signal` parameters.
The same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`transform`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#transform-it) abortable. Returns a new transform that wraps the passed `transform` and makes it abortable via the passed `signal` parameter.
127
+
128
+
### `abortable.transform(transform, signals)`
129
+
130
+
The same as [`abortable.source`](#abortablesource-signals) except this makes the passed [`transform`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#transform-it) abortable via any one of the passed `AbortSignal`'s. Returns a new transform that wraps the passed `transform` and makes it abortable via the passed `signal` parameters.
131
+
132
+
### `abortable.duplex(duplex, signal, [options])`
133
+
134
+
The same as [`abortable.source`](#abortablesource-signal-options) except this makes the passed [`duplex`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) abortable. Returns a new duplex that wraps the passed `duplex` and makes it abortable via the passed `signal` parameter.
135
+
136
+
Note that this will abort _both_ sides of the duplex. Use `duplex.sink = abortable.sink(duplex.sink)` or `duplex.source = abortable.source(duplex.source)` to abort just the sink or the source.
137
+
138
+
### `abortable.duplex(duplex, signals)`
139
+
140
+
The same as [`abortable.source`](#abortablesource-signals) except this makes the passed [`duplex`](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) abortable via any one of the passed `AbortSignal`'s. Returns a new duplex that wraps the passed `duplex` and makes it abortable via the passed `signal` parameters.
141
+
142
+
Note that this will abort _both_ sides of the duplex. Use `duplex.sink = abortable.sink(duplex.sink)` or `duplex.source = abortable.source(duplex.source)` to abort just the sink or the source.
143
+
102
144
## Related
103
145
104
146
*[`it-pipe`](https://www.npmjs.com/package/it-pipe) Utility to "pipe" async iterables together
0 commit comments