SlideShare uma empresa Scribd logo
1 de 53
#dotNetSpain2016
dotNet Spain Conference 2016
#dotNetSpain2016
Edin Kapić
SharePoint Practice Lead @ Sogeti Spain
edin@edinkapic.com
Rx, la joya oculta de
NET
Patrocinadores
Colaboradores
#dotNetSpain2016
#dotNetSpain2016
¿Rx?
Introducción
Rx
Observables
Sujetos
Tratamiento de secuencias
¡Rx!
Reimaginando nuestro código
Rx en en mundo real
Más allá de Rx
Agenda
#dotNetSpain2016
Senior Architect &
SharePoint Practice Lead
sug.cat
@ekapic
www.edinkapic.com
Presidente
Autor
#dotNetSpain2016
¿Rx?
#dotNetSpain2016
Rx (Reactive eXtensions) es una librería .NET que
permite hacer programación reactiva
#dotNetSpain2016
Un modelo de programación orientado a flujos de
datos y la propagación de los cambios
https://en.wikipedia.org/wiki/Reactive_programming
#dotNetSpain2016
#dotNetSpain2016
Rx = Observables + LINQ + Schedulers
Rx = LINQ-to-Events
IEnumerable = Pull, IObservable = Push
#dotNetSpain2016
• obs.Where(x=>x.ID == 1)
• Observable.Create()
Extensiones y
LINQ
• IObservable
• IObserver
• Subject
Flujos y eventos
• IScheduler
• Dispatchers
• Timers
Concurrencia
#dotNetSpain2016
NuGet Rx-Main
NuGet RxJS-Main
NPM Rx System.Reactive
#dotNetSpain2016
#dotNetSpain2016
Rx
static void Main(string[] args)
{
IObservable<char> obs = "Hello, world!".ToObservable();
obs.Subscribe(x =>
Console.WriteLine(x));
Console.ReadLine();
}
#dotNetSpain2016
Secuencia (flujo, stream) asíncrona de datos
namespace System
{
public interface IObservable<out T>
{
IDisposable Subscribe(IObserver<T> observer);
}
}
#dotNetSpain2016
El consumidor de una secuencia observable
namespace System
{
public interface IObserver<in T>
{
void OnCompleted();
void OnError(Exception error);
void OnNext(T value);
}
}
Un momento,
¿esto no es algo
parecido a…
…enumerables?
…eventos?
#dotNetSpain2016
IObservable
IObserver
IEnumerable
IEnumerator
Push Pull
#dotNetSpain2016
Observable Evento
IObservable = Eventos+++
Vale, seguimos con
Rx…
#dotNetSpain2016
Subject es IObservable y IObserver a la vez
Útil para hacer de proxy entre los “clientes” y el
“origen” de datos
var subject = new Subject<string>();
subject.Subscribe(value => Console.WriteLine(value));
subject.OnNext("a");
subject.OnNext("b");
subject.OnNext("c");
#dotNetSpain2016
todos los
valores de la secuencia
el último valor
de la secuencia
el último
resultado de la
secuencia al acabar
#dotNetSpain2016
Suscripción
var sub =
IObservable.Subscribe(…);
Fin de suscripción
sub.Dispose();
#dotNetSpain2016

#dotNetSpain2016
Manualmente A partir de otras cosas
Muy bonito, pero
no le veo la utilidad
#dotNetSpain2016
#dotNetSpain2016
Filtrar Combinar Mapear Reducir
Where(x== 2)
Merge()
Select(f(x)) Sum()
Filtrar
Agrupar
Valores únicos
Partición
http://freecontent.manning.com/animated-
gifs/?s=reactive-extensions
#dotNetSpain2016
Select SelectMany
Select(x.ToLetter) Select(x.FromAToLetter)
#dotNetSpain2016
Count, Min, Max, Sum, Average
escalar
First, Last, Single
elemento
Aggregate, Scan
Función
Sum()
Un momento, no
he visto nada de
“secuencias en el
tiempo” todavía…
#dotNetSpain2016
Concat SwitchMerge
#dotNetSpain2016
public interface IScheduler
{
DateTimeOffset Now { get; }
IDisposable Schedule<TState>(TState state,
Func<IScheduler, TState, IDisposable> action);
IDisposable Schedule<TState>(TState state,
DateTimeOffset dueTime,
Func<IScheduler, TState, IDisposable> action);
IDisposable Schedule<TState>(TState state,
TimeSpan dueTime,
Func<IScheduler, TState, IDisposable> action);
}
#dotNetSpain2016
• new Thread(() => { /* do work */ }).Start()
• ThreadPool.QueueUserWorkItem(_ => { /* do work */ }, null)
• Task.Factory.StartNew(() => { /* do work */ })
• syncCtx.Post(_ => { /* do work */ }, null)
• Dispatcher.BeginInvoke(() => { /* do work */ })
• scheduler.Schedule(() => { /* do work */ })
#dotNetSpain2016
La mayoría de las operaciones de Rx usan schedulers
#dotNetSpain2016
#dotNetSpain2016
• ImmediateScheduler
• CurrentThreadScheduler
• NewThreadScheduler
• EventLoopScheduler
• HistoricalScheduler
• ControlScheduler
• DispatcherScheduler
• SynchronizationContextScheduler
• TaskPoolScheduler
• ThreadPoolScheduler
Implementados por la plataforma
#dotNetSpain2016
http://blogs.msdn.com/b/rxteam/archive/2012/06/14/testing-rx-queries-using-virtual-time-scheduling.aspx
#dotNetSpain2016
SubscribeOn
ObserveOn
#dotNetSpain2016
¡Rx!
#dotNetSpain2016
Código que gestiona
llamadas asíncronas o
eventos
Código que manipula
secuencias asíncronas
de datos
https://github.com/AdaptiveConsulting/ReactiveTrader
#dotNetSpain2016
#dotNetSpain2016
#dotNetSpain2016
Ix (Interactive Expressions)
#dotNetSpain2016
IQbservable<T>
#dotNetSpain2016
Tx
#dotNetSpain2016
ReactiveUI
https://github.com/reactiveui
Recursos
#dotNetSpain2016
Código fuente
https://github.com/Reactive-Extensions/Rx.NET
https://github.com/ekapic/Rx-Dns2016
Tutoriales
http://introtorx.com/
http://reactivex.io
https://msdn.microsoft.com/en-us/data/gg577609
https://manning.com/books/reactive-extensions-in-action
Q&A
#dotNetSpain2016
http://aka.ms/DOTNETT7S5
No olvides realizar la encuesta
¡Gracias!
#dotNetSpain2016
Edin Kapić
SharePoint Practice Lead @ Sogeti Spain
edin@edinkapic.com
http://aka.ms/DOTNETT7S5

Mais conteúdo relacionado

Semelhante a Rx la joya oculta de Net

ganttproject & ganttpv
ganttproject & ganttpvganttproject & ganttpv
ganttproject & ganttpv
griscar7772
 
Matlab
MatlabMatlab
Matlab
ford81
 

Semelhante a Rx la joya oculta de Net (20)

Asp.Net Core 1.0 Deep Dive
Asp.Net Core 1.0 Deep DiveAsp.Net Core 1.0 Deep Dive
Asp.Net Core 1.0 Deep Dive
 
Roslyn: Hello from the other compiler - dotNet Spain Conference 2016
Roslyn: Hello from the other compiler - dotNet Spain Conference 2016Roslyn: Hello from the other compiler - dotNet Spain Conference 2016
Roslyn: Hello from the other compiler - dotNet Spain Conference 2016
 
Como hacer tuning a capas de acceso a datos en .NET (dotNetConference2016)
Como hacer tuning a capas de acceso a datos en .NET (dotNetConference2016)Como hacer tuning a capas de acceso a datos en .NET (dotNetConference2016)
Como hacer tuning a capas de acceso a datos en .NET (dotNetConference2016)
 
Reactvolution
ReactvolutionReactvolution
Reactvolution
 
ganttproject & ganttpv
ganttproject & ganttpvganttproject & ganttpv
ganttproject & ganttpv
 
Prensentacion ganttproject & ganttpv
Prensentacion ganttproject & ganttpvPrensentacion ganttproject & ganttpv
Prensentacion ganttproject & ganttpv
 
CrossDvlpu - REACT para desarrolladores de ASP.NET
CrossDvlpu - REACT para desarrolladores de ASP.NETCrossDvlpu - REACT para desarrolladores de ASP.NET
CrossDvlpu - REACT para desarrolladores de ASP.NET
 
Cross development - React para desarrolladores de asp.net
Cross development - React para desarrolladores de asp.netCross development - React para desarrolladores de asp.net
Cross development - React para desarrolladores de asp.net
 
.NET Core 1.0 y ASP.NET Core 1.0
.NET Core 1.0 y ASP.NET Core 1.0.NET Core 1.0 y ASP.NET Core 1.0
.NET Core 1.0 y ASP.NET Core 1.0
 
Directori català de l’economia col·laborativa
Directori català de l’economia col·laborativaDirectori català de l’economia col·laborativa
Directori català de l’economia col·laborativa
 
Matlab
MatlabMatlab
Matlab
 
Matlab (1)
Matlab (1)Matlab (1)
Matlab (1)
 
Revelando los secretos de twitter, Festival de Software Libre 2014
Revelando los secretos de twitter, Festival de Software Libre 2014Revelando los secretos de twitter, Festival de Software Libre 2014
Revelando los secretos de twitter, Festival de Software Libre 2014
 
Mirando a Alfresco desde Minecraft
Mirando a Alfresco desde MinecraftMirando a Alfresco desde Minecraft
Mirando a Alfresco desde Minecraft
 
¿Que es Openerp?
¿Que es Openerp?¿Que es Openerp?
¿Que es Openerp?
 
Power bi para desarrolladores
Power bi para desarrolladoresPower bi para desarrolladores
Power bi para desarrolladores
 
Taller IoT: desarrollo visual en Sofia2 con Raspberry Pi, Node-RED y dashboards
Taller IoT: desarrollo visual en Sofia2 con Raspberry Pi, Node-RED y dashboardsTaller IoT: desarrollo visual en Sofia2 con Raspberry Pi, Node-RED y dashboards
Taller IoT: desarrollo visual en Sofia2 con Raspberry Pi, Node-RED y dashboards
 
Hx c27
Hx c27Hx c27
Hx c27
 
Scala: La escalera a la Programación Funcional
Scala: La escalera a la Programación FuncionalScala: La escalera a la Programación Funcional
Scala: La escalera a la Programación Funcional
 
Archicad colaboracion abierta 4
Archicad colaboracion abierta 4Archicad colaboracion abierta 4
Archicad colaboracion abierta 4
 

Mais de Edin Kapic

SPS London 2015 - IoT and Room Reservation Cloud-Style
SPS London 2015 - IoT and Room Reservation Cloud-StyleSPS London 2015 - IoT and Room Reservation Cloud-Style
SPS London 2015 - IoT and Room Reservation Cloud-Style
Edin Kapic
 
SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)
SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)
SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)
Edin Kapic
 

Mais de Edin Kapic (20)

High-Trust Add-Ins SharePoint for On-Premises Development
High-Trust Add-Ins SharePoint for On-Premises DevelopmentHigh-Trust Add-Ins SharePoint for On-Premises Development
High-Trust Add-Ins SharePoint for On-Premises Development
 
Extending Authentication and Authorization
Extending Authentication and AuthorizationExtending Authentication and Authorization
Extending Authentication and Authorization
 
ESPC15 - Extending Authentication and Authorization
ESPC15 - Extending Authentication and AuthorizationESPC15 - Extending Authentication and Authorization
ESPC15 - Extending Authentication and Authorization
 
SPS London 2015 - IoT and Room Reservation Cloud-Style
SPS London 2015 - IoT and Room Reservation Cloud-StyleSPS London 2015 - IoT and Room Reservation Cloud-Style
SPS London 2015 - IoT and Room Reservation Cloud-Style
 
SPS Belgium 2015 - High-trust Apps for On-Premises Development
SPS Belgium 2015 -  High-trust Apps for On-Premises DevelopmentSPS Belgium 2015 -  High-trust Apps for On-Premises Development
SPS Belgium 2015 - High-trust Apps for On-Premises Development
 
Personal Branding for Developers
Personal Branding for DevelopersPersonal Branding for Developers
Personal Branding for Developers
 
SharePoint Saturday Stockholm 2015 - Building Maintainable and Testable Share...
SharePoint Saturday Stockholm 2015 - Building Maintainable and Testable Share...SharePoint Saturday Stockholm 2015 - Building Maintainable and Testable Share...
SharePoint Saturday Stockholm 2015 - Building Maintainable and Testable Share...
 
ESPC14 Social Business Value Demystified
ESPC14 Social Business Value DemystifiedESPC14 Social Business Value Demystified
ESPC14 Social Business Value Demystified
 
Maintainable Testable SharePoint Components SPSBE 2014
Maintainable Testable SharePoint Components SPSBE 2014Maintainable Testable SharePoint Components SPSBE 2014
Maintainable Testable SharePoint Components SPSBE 2014
 
MVP Open Day 2014 - Hacking Human Behaviour
MVP Open Day 2014 - Hacking Human BehaviourMVP Open Day 2014 - Hacking Human Behaviour
MVP Open Day 2014 - Hacking Human Behaviour
 
SPS Stockholm 7 Key Things for Building a Highly-Scalable SharePoint 2013 App
SPS Stockholm 7 Key Things for Building a Highly-Scalable SharePoint 2013 AppSPS Stockholm 7 Key Things for Building a Highly-Scalable SharePoint 2013 App
SPS Stockholm 7 Key Things for Building a Highly-Scalable SharePoint 2013 App
 
7 Key Things for Building a Highly-Scalable SharePoint 2013 App
7 Key Things for Building a Highly-Scalable SharePoint 2013 App7 Key Things for Building a Highly-Scalable SharePoint 2013 App
7 Key Things for Building a Highly-Scalable SharePoint 2013 App
 
Social Business Value Demystified: Real-World Experiences
Social Business Value Demystified: Real-World ExperiencesSocial Business Value Demystified: Real-World Experiences
Social Business Value Demystified: Real-World Experiences
 
BcnDevCon13 - No Designer? No Problem!
BcnDevCon13 - No Designer? No Problem!BcnDevCon13 - No Designer? No Problem!
BcnDevCon13 - No Designer? No Problem!
 
BcnDevCon12 - Una vuelta por Orchard CMS
BcnDevCon12 - Una vuelta por Orchard CMSBcnDevCon12 - Una vuelta por Orchard CMS
BcnDevCon12 - Una vuelta por Orchard CMS
 
BcnDevCon12 - CQRS explicado a mi compañero arquitecto
BcnDevCon12 - CQRS explicado a mi compañero arquitectoBcnDevCon12 - CQRS explicado a mi compañero arquitecto
BcnDevCon12 - CQRS explicado a mi compañero arquitecto
 
Modelos de madurez de SharePoint
Modelos de madurez de SharePointModelos de madurez de SharePoint
Modelos de madurez de SharePoint
 
SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)
SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)
SharePoint 2013 Novedades y más allá (Introducción de SUG.CAT)
 
SUG.CAT First Monday Noviembre 2012
SUG.CAT First Monday Noviembre 2012SUG.CAT First Monday Noviembre 2012
SUG.CAT First Monday Noviembre 2012
 
JavaScript per a desenvolupadors de C#
JavaScript per a desenvolupadors de C#JavaScript per a desenvolupadors de C#
JavaScript per a desenvolupadors de C#
 

Rx la joya oculta de Net