Git Product home page Git Product logo

Comments (12)

yevhen avatar yevhen commented on May 28, 2024

Which version you are on now?

from orleankka.

mhertis avatar mhertis commented on May 28, 2024

0.23.0

from orleankka.

yevhen avatar yevhen commented on May 28, 2024

ye, that's old. Do you use declarative stream subscriptions?

from orleankka.

mhertis avatar mhertis commented on May 28, 2024

No, in this case, we are using explicit subscriptions.

from orleankka.

yevhen avatar yevhen commented on May 28, 2024

If you're not using declarative stream subscriptions - you can try latest version (I'll push update today) there this was fixed.

from orleankka.

mhertis avatar mhertis commented on May 28, 2024

We are using declarative stream subscriptions on some other parts of the application. I can't update until we figure out migration path for declarative subscriptions.

But I can make some reflection magic, to mimic fixes of the latest version.

from orleankka.

yevhen avatar yevhen commented on May 28, 2024

yep, should not be hard ))

from orleankka.

yevhen avatar yevhen commented on May 28, 2024

https://github.com/OrleansContrib/Orleankka/blob/v1/Source/Orleankka/StreamSubscription.cs#L13 get this one by reflection

from orleankka.

mhertis avatar mhertis commented on May 28, 2024

It almost works. =D

 static class StreamSubscriptionExtensions
    {
        private static readonly FieldInfo handle = typeof(StreamSubscription).GetTypeInfo().GetDeclaredField("handle");
        private static readonly MethodInfo GetAllSubscriptionHandles = typeof(StreamRef).GetTypeInfo().GetDeclaredMethod("GetAllSubscriptionHandles");

        /// <summary>
        ///   Returns a list of all current stream subscriptions.
        /// </summary>
        /// <returns> A promise for a list of StreamSubscription </returns>
        public static async Task<List<StreamSubscription>> Subscriptions(this StreamRef streamRef)
        {
            var handles = await (Task<IList<StreamSubscriptionHandle<object>>>)GetAllSubscriptionHandles.Invoke(streamRef, null);

            return handles.Select(CreateStreamSubscription).ToList();
        }

        private static StreamSubscription CreateStreamSubscription(StreamSubscriptionHandle<object> x)
        {
            return Activator.CreateInstance(typeof(StreamSubscription), BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { x }, null, null) as StreamSubscription;
        }

        public static Task Resume(this StreamSubscription streamSubscription, Func<object, Task> callback)
        {
            Requires.NotNull(callback, nameof(callback));
            var observer = new Observer((item, token) => callback(item));
            var subscriptionHandle = (StreamSubscriptionHandle<object>)handle.GetValue(streamSubscription);

            return subscriptionHandle.ResumeAsync(observer);
        }

        public static Task Resume<T>(this StreamSubscription streamSubscription, Func<T, Task> callback)
        {
            Requires.NotNull(callback, nameof(callback));
            return streamSubscription.Resume(item => callback((T)item));
        }

        class Observer : IAsyncObserver<object>
        {
            readonly Func<object, StreamSequenceToken, Task> callback;

            public Observer(Func<object, StreamSequenceToken, Task> callback)
            {
                this.callback = callback;
            }

            public Task OnNextAsync(object item, StreamSequenceToken token = null)
                => callback(item, token);

            public Task OnCompletedAsync() => Task.CompletedTask;
            public Task OnErrorAsync(Exception ex) => Task.CompletedTask;
        }
    }

After calling StreamSubscription.Resume, StreamSubscriptionHandle.observer remains null. I will just unsubscribe all subscriptions and resubscribe, for now. =D

from orleankka.

yevhen avatar yevhen commented on May 28, 2024

I've never understood why Orleans guys had not implemented subscriptions in idempotent way. Duplicate subscriptions from the same client/actor in 100% of cases is a mistake.

P.S. "StreamSubscriptionHandle.observer remains null" might be a normal behavior. Check Orleans code ..

from orleankka.

mhertis avatar mhertis commented on May 28, 2024

I totally agree with you and now I have discovered one more surprise...

subscriptionHandle.ResumeAsync(observer) returns Task<StreamSubscriptionHandle<object>> - > new valid handle while old handle becomes invalid.

I think that latest Orleankka codebase does not take this behavior into account.

from orleankka.

yevhen avatar yevhen commented on May 28, 2024

Nice catch!

from orleankka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.