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
Copy file name to clipboardexpand all lines: packages/eslint-plugin/docs/rules/await-thenable.mdx
+57-1
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ This rule also inspects [`for await...of` statements](https://developer.mozilla.
49
49
While `for await...of` can be used with synchronous iterables, and it will await each promise produced by the iterable, it is inadvisable to do so.
50
50
There are some tiny nuances that you may want to consider.
51
51
52
-
The biggest difference between using `for await...of` and using `for...of` (plus awaiting each result yourself) is error handling.
52
+
The biggest difference between using `for await...of` and using `for...of` (apart from awaiting each result yourself) is error handling.
53
53
When an error occurs within the loop body, `for await...of` does _not_ close the original sync iterable, while `for...of` does.
54
54
For detailed examples of this, see the [MDN documentation on using `for await...of` with sync-iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of#iterating_over_sync_iterables_and_generators).
55
55
@@ -120,6 +120,62 @@ async function validUseOfForAwaitOnAsyncIterable() {
This rule also inspects [`await using` statements](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management).
126
+
If the disposable being used is not async-disposable, an `await using` statement is unnecessary.
127
+
128
+
### Examples
129
+
130
+
<Tabs>
131
+
<TabItemvalue="❌ Incorrect">
132
+
133
+
```ts
134
+
function makeSyncDisposable():Disposable {
135
+
return {
136
+
[Symbol.dispose]():void {
137
+
// Dispose of the resource
138
+
},
139
+
};
140
+
}
141
+
142
+
asyncfunction shouldNotAwait() {
143
+
awaitusingresource=makeSyncDisposable();
144
+
}
145
+
```
146
+
147
+
</TabItem>
148
+
<TabItemvalue="✅ Correct">
149
+
150
+
```ts
151
+
function makeSyncDisposable():Disposable {
152
+
return {
153
+
[Symbol.dispose]():void {
154
+
// Dispose of the resource
155
+
},
156
+
};
157
+
}
158
+
159
+
asyncfunction shouldNotAwait() {
160
+
usingresource=makeSyncDisposable();
161
+
}
162
+
163
+
function makeAsyncDisposable():AsyncDisposable {
164
+
return {
165
+
async [Symbol.asyncDispose]():Promise<void> {
166
+
// Dispose of the resource asynchronously
167
+
},
168
+
};
169
+
}
170
+
171
+
asyncfunction shouldAwait() {
172
+
awaitusingresource=makeAsyncDisposable();
173
+
}
174
+
```
175
+
176
+
</TabItem>
177
+
</Tabs>
178
+
123
179
## When Not To Use It
124
180
125
181
If you want to allow code to `await` non-Promise values.
0 commit comments