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
I think exposing Scope as the only way to attach a Context is great, but I think it would be good if the ContextStorage exposes a low-level APIs attach/detach or something similar that do not require a new object all the time.
Example:
/** * Returns a {@link Runnable} that makes this the {@linkplain Context#current() current context} * and then invokes the input {@link Runnable}. */defaultRunnablewrap(Runnablerunnable) {
return () -> {
try (Scopeignored = makeCurrent()) {
runnable.run();
}
};
}
This code needs 2 allocations (one for the return Runnable, and will do an allocation when makeCurrent is called), but we can in this case re-write this like:
/** * Returns a {@link Runnable} that makes this the {@linkplain Context#current() current context} * and then invokes the input {@link Runnable}. */defaultRunnablewrap(Runnablerunnable) {
return () -> {
ContexttoDetach = storage.attach(this);
try () {
runnable.run();
} finally {
storage.detach(toDetach);
}
};
}
The attach/detach APIs are for example, probably we need better APIs for that and we need to think about them.
The text was updated successfully, but these errors were encountered:
I found interop with context storage implementations that use detach pattern harder since you have to implement the actual context class itself to keep track of how to restore, assuming it's not a class anyways. For example here
@anuraaga but can we avoid that extra unnecessary allocation? Another option is to have both APIs on the Storage, so only when really needed you use the low-level once.
I actually think we can do this after 1.0 and have something like attachUnsafe and detachUnsafe as an example.
I think exposing
Scope
as the only way to attach a Context is great, but I think it would be good if the ContextStorage exposes a low-level APIs attach/detach or something similar that do not require a new object all the time.Example:
This code needs 2 allocations (one for the return Runnable, and will do an allocation when makeCurrent is called), but we can in this case re-write this like:
The attach/detach APIs are for example, probably we need better APIs for that and we need to think about them.
The text was updated successfully, but these errors were encountered: