Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change request] StreamSubscription.cancel can no longer return null #40676

Closed
lrhn opened this issue Feb 19, 2020 · 8 comments
Closed
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. breaking-change-request This tracks requests for feedback on breaking changes library-async
Milestone

Comments

@lrhn
Copy link
Member

lrhn commented Feb 19, 2020

Summary

The StreamSubscription.cancel method's return type is changed to Future<void>.

What is changing:

We change the return type of StreamSubscription.cancel to Future<void>.
The return type will be non-nullable in Null Safe code, and you are not allowed to return null.

Why is this changing?

The StreamSubscription.cancel method currently has a return type of Future (aka. Future<dynamic>). It allows you to return null as well, but this has been discouraged since the release of Dart 1, it's just not something the type system could prevent.

When migrating this method to Null Safety, we have decided to change the return type to Future<void> (non-nullable). That means that implementations of the StreamSubscription class can no longer return a null value, and you can no longer use the value of the returned future without casting the Future away from void first.
That is considered reasonable because the future is not intended to contain any useful value.

If a specific user of a specific stream subscription happens to know that that stream subscription's cancel returns a future with a useful value, then that should be reflected by having a sub-class of stream subscription with a different return type. (Or, as a hack, by casting the Future<void> to Future<dynamic> or similar before using it).

Expected impact

The type change disallows code which currently awaits the returned future and uses its value.
That code needs to cast the future to something else first, so the result won't have type void.

The non-null part won't be enforced until Null Safety, at which point tools will help find places where null is currently returned. That code should then return Future<Null>.value(null).

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-async breaking-change-request This tracks requests for feedback on breaking changes labels Feb 19, 2020
@franklinyow
Copy link
Contributor

cc @Hixie @matanlurey @dgrove @vsmenon for review and approval.

@matanlurey
Copy link
Contributor

LGTM

@franklinyow franklinyow added this to the D28 Release milestone Feb 25, 2020
@leafpetersen
Copy link
Member

ping on this.

@franklinyow
Copy link
Contributor

Ping again @Hixie @vsmenon

@Hixie
Copy link
Contributor

Hixie commented Mar 4, 2020

assuming there's no code seriously broken by this, lgtm

@vsmenon
Copy link
Member

vsmenon commented Mar 5, 2020

lgtm

@franklinyow
Copy link
Contributor

Approved

@leafpetersen
Copy link
Member

This has landed in bleeding edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. breaking-change-request This tracks requests for feedback on breaking changes library-async
Projects
None yet
Development

No branches or pull requests

6 participants