Skip to content

Instantly share code, notes, and snippets.

@forki
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forki/8902210 to your computer and use it in GitHub Desktop.
Save forki/8902210 to your computer and use it in GitHub Desktop.
Rx + async
public static void RegisterConnection(string connectionId, string company, string processId)
{
var observable =
Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(2))
.SelectMany(_ => Observable.FromAsync(() => ProcessService.GetProcessChangeTimeAsync(company, processId)))
.Distinct()
.SelectMany(_ => Observable.FromAsync(() => ProcessService.GetDiagramDataAsync(company, processId)));
var subscription = observable.Subscribe(json => _hub.Clients.Client(connectionId).loadProcess(json));
Subscriptions.Add(connectionId, subscription);
}
@forki
Copy link
Author

forki commented Feb 9, 2014

second version. SelectMany instead of Select + concat

But still why do I have to use Observable.FromAsync and the SelectMany - why no overload at Select which takes an async method

@blacktaxi
Copy link

I think there's a SelectMany overload that takes a Task<T>, so you can loose the Observable.FromAsync.

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