Skip to content

Add instrumentation to enhanced for when iterating suspendable Iterables #285

Description

@FroMage

Hi,

I'm trying a suspendable Iterable and I can't get it to work in enhanced for loops, probably due to the instrumentation not detecting that the Iterator has @Suspendable in its next() method definition.

Would it be possible to add support in instrumenting for loops, where the iterated element has a suspendable iterator as determined statically?

In my case, I'm doing:

class SuspendableIterable<T> implements Iterable<T> {
 @Override
 public SuspendableIterator<T> iterator() {
  return new SuspendableIterator<>(...);
 }
}
class SuspendableIterator<T> implements Iterator<T> {
 @Override
 @Suspendable
 public T next() {
  ...
 }
 @Override
 @Suspendable
 public boolean hasNext() {
  ...
 }
 ...
}

SuspendableIterable<Integer> it = ...;
for(int i : it){
}

And this breaks because the instrumentation does not detect that the for loop will call hasNext/next which are suspendable. I think this can be determined statically, no?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions