{"action":"opened","issue":{"url":"https://api.github.com/repos/Reactive-Extensions/Rx.NET/issues/249","repository_url":"https://api.github.com/repos/Reactive-Extensions/Rx.NET","labels_url":"https://api.github.com/repos/Reactive-Extensions/Rx.NET/issues/249/labels{/name}","comments_url":"https://api.github.com/repos/Reactive-Extensions/Rx.NET/issues/249/comments","events_url":"https://api.github.com/repos/Reactive-Extensions/Rx.NET/issues/249/events","html_url":"https://github.com/Reactive-Extensions/Rx.NET/issues/249","id":169794640,"number":249,"title":"Relaying values from more than one observable using a Subject<T> does not work if the subject subscribes to the sources on the same thread","user":{"login":"Sathyaish","id":7037893,"avatar_url":"https://avatars.githubusercontent.com/u/7037893?v=3","gravatar_id":"","url":"https://api.github.com/users/Sathyaish","html_url":"https://github.com/Sathyaish","followers_url":"https://api.github.com/users/Sathyaish/followers","following_url":"https://api.github.com/users/Sathyaish/following{/other_user}","gists_url":"https://api.github.com/users/Sathyaish/gists{/gist_id}","starred_url":"https://api.github.com/users/Sathyaish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sathyaish/subscriptions","organizations_url":"https://api.github.com/users/Sathyaish/orgs","repos_url":"https://api.github.com/users/Sathyaish/repos","events_url":"https://api.github.com/users/Sathyaish/events{/privacy}","received_events_url":"https://api.github.com/users/Sathyaish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-07T12:43:28Z","updated_at":"2016-08-07T12:43:28Z","closed_at":null,"body":"If we use a subject to subscribe to two or more observables and propagate the values from those observables to the observers of the subject, only the values of the first observable are propagated to the observers; the values from observables other than the first observable are not propagated. This happens only if the subject subscribes to and observes values from all the observables on the current thread.\r\n\r\nIf, however, the subject subscribes to the source observables on any other thread, for e.g. using the task pool or the thread pool schedulers or a new thread scheduler, the values all the observables are propagated.\r\n\r\nTo illustrate, please consider the code snippet below.\r\n\r\n```\r\nusing System;\r\nusing System.Reactive.Subjects;\r\nusing System.Reactive.Linq;\r\nusing System.Diagnostics;\r\nusing System.Threading;\r\nusing System.Reactive.Concurrency;\r\n\r\nnamespace FourStepsUsingSubject\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            Demo();\r\n\r\n            Console.WriteLine(\"Press any key to exit the program...\");\r\n            Console.ReadKey();\r\n        }\r\n\r\n        static void Demo()\r\n        {\r\n            // Using a subject as a broadcast or relay service\r\n            // That is, a mediator that subscribes to many observables\r\n            // and then relays its values to its observers\r\n            var subject = new Subject<string>();\r\n\r\n            var s1 = subject.Subscribe(Program.PrintToConsole);\r\n            var s2 = subject.Subscribe(Program.PrintToDebugWindow);\r\n            var s3 = subject.Subscribe(Program.PrintToConsoleSlowly);\r\n\r\n            var o1 = new[] { \"Hello\", \"World\" }.ToObservable();\r\n            var o2 = new[] { \"Sunday\", \"Monday\", \"Tuesday\" }.ToObservable();\r\n\r\n            // Only proagates o1's values. Does not proagate o2's values\r\n            //var s4 = o1.ObserveOn(Scheduler.CurrentThread).Subscribe(subject);\r\n\r\n            // Only proagates o1's values. Does not proagate o2's values\r\n            //var s4 = o1.ObserveOn(Scheduler.Immediate).Subscribe(subject);\r\n\r\n            // Propagates both o1's and o2's values\r\n            //var s4 = o1.ObserveOn(Scheduler.Default).Subscribe(subject);\r\n\r\n            // Only proagates o1's values. Does not proagate o2's values\r\n            var s4 = o1.Subscribe(subject);\r\n\r\n            var s5 = o2.Subscribe(subject);\r\n\r\n            Console.WriteLine(\"\\nPress any key to dispose all subscriptions.\");\r\n            s1.Dispose();\r\n            s2.Dispose();\r\n            s3.Dispose();\r\n            s4.Dispose();\r\n            s5.Dispose();\r\n        }\r\n\r\n        static void PrintToConsole(string message)\r\n        {\r\n            Console.WriteLine(message);\r\n        }\r\n\r\n        static void PrintToConsoleSlowly(string message)\r\n        {\r\n            Thread.Sleep(500);\r\n            Console.WriteLine(message + \" slowly...\");\r\n        }\r\n\r\n        static void PrintToDebugWindow(string message)\r\n        {\r\n            Debug.Print(message);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nI will rework it into a unit test and submit at my earliest convenience."}}
{"actor":{"display_login":"Sathyaish"}}