Skip to content

api: Add a Supplier overload to Context - #12935

Open
carl-mastrangelo wants to merge 3 commits into
grpc:masterfrom
carl-mastrangelo:contextsupplier
Open

api: Add a Supplier overload to Context#12935
carl-mastrangelo wants to merge 3 commits into
grpc:masterfrom
carl-mastrangelo:contextsupplier

Conversation

@carl-mastrangelo

Copy link
Copy Markdown
Contributor

Fixes #12927

@carl-mastrangelo

Copy link
Copy Markdown
Contributor Author

[Undefined reference | android-api-level-21-5.0.1_r2] io.grpc.(Context.java:568)

@carl-mastrangelo

Copy link
Copy Markdown
Contributor Author

#12936 Appears to be needed.

assertSame(current, Context.current());

final TestError err = new TestError();
try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestError caught = assertThrows(TestError.class, ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel strongly I can, but I was keeping the style of the tests around it.

@kannanjgithub kannanjgithub added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Jul 28, 2026
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Jul 28, 2026
@carl-mastrangelo

Copy link
Copy Markdown
Contributor Author

@kannanjgithub @ejona86 Looks like context is Java7? Any chance

tasks.named("compileContextJava").configure {
could be revisited?

@ejona86 ejona86 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supply() is a bit of a weird name. But get() would be even weirder.

Mark it experimental like normal? (Just with a comment, since we can't use the annotation here.)

Yeah, I think we could drop Java 7 and compile with Java 8. It's been 4.5 years since we dropped Java 7. We should probably keep the separate compilation step as when we drop Java 8 we'll probably want Context to again stay on Java 8 for a while.

* @param supplier {@link Supplier} to use to produce the value.
* @return result of supplier.
*/
@CanIgnoreReturnValue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit strange. Did we only ignore call() because of existing callers? Hey, look! @carl-mastrangelo reviewed #4430 😛

I guess people could be doing Callable<Void> if they wanted a Runnable that could throw exceptions. I don't think there's any point to ignoring a Supplier's return value though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, Callable<Void> shouldn't even need @CanIgnoreReturnValue. So I guess we did it just because there were existing callers.

@carl-mastrangelo carl-mastrangelo Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely don't like the name supply, but also can't really use an overload of call. I'm open to alternatives. invoke() ? callInContext() ? apply() ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I sent out #12955 to update the context version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Supplier overload to Context

5 participants