Example #1
0
            static void ForeignFunctions2()
            {
                using var environment = new InMemoryReactiveEnvironment();
                using var platform    = new InMemoryReactivePlatform(environment);

                Initialize(environment, platform);

                var ctx = platform.CreateClient().Context;

                Console.WriteLine("Creating stream...");

                var streamFactory = ctx.GetStreamFactory <Person, Person>(Platform.Constants.Identifiers.Observable.FireHose.Uri);
                var stream        = streamFactory.CreateAsync(new Uri("reactor://stream/foo"), null).Result;

                var people = ctx.GetObservable <Person>(new Uri("reactor://stream/foo"));
                var cout   = ctx.GetObserver <string>(Platform.Constants.Identifiers.Observer.ConsoleObserver.Uri);

                Console.WriteLine("Creating subscription...");

                var sub = people
                          .Select(p => Json.Serialize(p)) // NB: fast serialization doesn't work at the moment; no support for enums yet
                          .SubscribeAsync(cout, new Uri("reactor://test/subscription"), null).Result;

                Console.WriteLine("Publishing events...");

                var observer = ctx.GetObserver <Person>(new Uri("reactor://stream/foo"));

                observer.OnNextAsync(new Person {
                    FirstName = "John", LastName = "Smith", Location = "Home"
                }).Wait();
                observer.OnNextAsync(new Person {
                    FirstName = "Bob", LastName = "Smith", Location = "Home"
                }).Wait();
                observer.OnNextAsync(new Person {
                    FirstName = "Joe", LastName = "Smith", Location = "Home"
                }).Wait();

                Task.Delay(10000).Wait();

                sub.DisposeAsync().Wait();
            }
Example #2
0
            static void ForeignFunctions1()
            {
                using var environment = new InMemoryReactiveEnvironment();
                using var platform    = new InMemoryReactivePlatform(environment);

                Initialize(environment, platform);

                var ctx = platform.CreateClient().Context;

                var range = ctx.GetObservable <int, int>(Reactor.Constants.Identifiers.Observable.Range.Uri);
                var cout  = ctx.GetObserver <string>(Platform.Constants.Identifiers.Observer.ConsoleObserver.Uri);

                Console.WriteLine("Press ENTER to dispose...");

                var sub = range(5)
                          .Select(value => GenerateLanguage(value, "en-us"))
                          .SubscribeAsync(cout, new Uri("reactor://test/subscription"), null).Result;

                Task.Delay(1000).Wait();

                sub.DisposeAsync().Wait();
            }