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

Resolver: Coroutine doesn't repeat when Resolve becomes false #55

Open
mattwehner opened this issue Jul 29, 2023 · 0 comments
Open

Resolver: Coroutine doesn't repeat when Resolve becomes false #55

mattwehner opened this issue Jul 29, 2023 · 0 comments

Comments

@mattwehner
Copy link

If a Resolver is created and the first loop of resolveContinuously() is run before Resolve becomes true then the coroutine will not be run again.
It works in the Complex Outlet Inlet sample because the subscriber registers before the next while loop.

Any subscriber afterwards only benefit from using the resolver if Resolve remains true during the lifetime of the resolver. This limits the scalability of using Resolvers in a project.

The coroutine could be moved to run in the Update loop:

private void Update(){ 
   if(!Resolve) return; 
   .... 
}

Or for the coroutine to be started/stopped on change in subscribers:

public class Resolver : MonoBehaviour
    {
...
        private Coroutine _resolveRoutine;
        
        private StreamFound _onStreamFound;
        public StreamFound OnStreamFound
        {
            get => _onStreamFound;
            set
            {
                _onStreamFound = value;
                if (_onStreamFound != null && _resolveRoutine == null)
                {
                    _resolveRoutine = StartCoroutine(resolveContinuously());
                }
            }
        }

        private StreamLost _onStreamLost;

        public StreamLost OnStreamLost
        {
            get => _onStreamLost;
            set
            {
                _onStreamLost = value;
                if (_onStreamFound != null && _resolveRoutine == null)
                {
                    _resolveRoutine = StartCoroutine(resolveContinuously());
                }
            }
        }
       ...
        public void Start()
        {
            resolver = new ContinuousResolver(forgetStreamAfter);
            _resolveRoutine = StartCoroutine(resolveContinuously());
        }

        ...

        private IEnumerator resolveContinuously()
        {
            while (Resolve)
            {
                ...
            }

            yield return null;
            _resolveRoutine = null;
        }
    }
}
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

No branches or pull requests

1 participant