Skip to content

Commit 6f15262

Browse files
authored
chore: in a library, every unawaited future should be intentional (#25)
1 parent f26fc20 commit 6f15262

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ linter:
3030
- avoid_returning_this
3131
- avoid_void_async
3232
- directives_ordering
33+
- discarded_futures
34+
- library_private_types_in_public_api
3335
- omit_local_variable_types
3436
- parameter_assignments
3537
- prefer_asserts_with_message
@@ -51,6 +53,5 @@ linter:
5153
# - avoid_catches_without_on_clauses (sometimes catching all exceptions is intentional)
5254
# - avoid_dynamic_calls (necessary when working with JSON/dynamic data)
5355
# - cascade_invocations (not always clearer)
54-
# - discarded_futures (fire-and-forget is sometimes intentional)
5556
# - lines_longer_than_80_chars (too restrictive for modern screens)
5657
# - prefer_expression_function_bodies (block bodies can be clearer)

example/basic/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ final isProduction = defineBoolean(
3232
),
3333
);
3434

35-
void main(List<String> args) {
36-
fireUp(args, (firebase) {
35+
void main(List<String> args) async {
36+
await fireUp(args, (firebase) {
3737
// ==========================================================================
3838
// HTTPS Callable Functions (onCall / onCallWithData)
3939
// ==========================================================================

example/firestore_test/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:firebase_functions/firebase_functions.dart';
22

3-
void main(List<String> args) {
4-
fireUp(args, (firebase) {
3+
void main(List<String> args) async {
4+
await fireUp(args, (firebase) {
55
// Test Firestore onDocumentCreated with wildcard
66
firebase.firestore.onDocumentCreated(document: 'users/{userId}', (
77
event,

example/with_options/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'package:firebase_functions/firebase_functions.dart';
22

33
/// Comprehensive example testing ALL HTTP function options.
44
/// This validates that the builder correctly extracts and exports all 21 options.
5-
void main(List<String> args) {
6-
fireUp(args, (firebase) {
5+
void main(List<String> args) async {
6+
await fireUp(args, (firebase) async {
77
// Test 1: HTTPS onRequest with ALL GlobalOptions + cors
88
firebase.https.onRequest(
99
name: 'httpsFull',

lib/src/https/callable.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class CallableResponse<T extends Object> {
224224

225225
_streamSubscription = dataStream.listen(
226226
(result) {
227-
sendChunk(result.data);
227+
unawaited(sendChunk(result.data));
228228
},
229229
onError: (Object error) {
230230
// Log error but don't close the stream - let handler complete
@@ -297,7 +297,7 @@ class CallableResponse<T extends Object> {
297297
/// Marks the stream as aborted.
298298
void abort() {
299299
_aborted = true;
300-
_streamSubscription?.cancel();
300+
unawaited(_streamSubscription?.cancel());
301301
_streamSubscription = null;
302302
clearHeartbeat();
303303
}

test/unit/https_callable_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void main() {
255255
expect(response.streamingResponse!.headers['Connection'], 'keep-alive');
256256

257257
// Cleanup
258-
response.closeStream();
258+
unawaited(response.closeStream());
259259
});
260260

261261
test('sendChunk returns false when not streaming', () async {
@@ -339,7 +339,7 @@ void main() {
339339
// Just verify it doesn't throw
340340
response.clearHeartbeat();
341341

342-
response.closeStream();
342+
unawaited(response.closeStream());
343343
});
344344

345345
test('stream method forwards stream data', () async {

0 commit comments

Comments
 (0)