SlideShare a Scribd company logo
1 of 24
Download to read offline
How to meets
Async and Task
2016.11.08 MVP SUMMIT SPECIAL: A NIGHT OF LIGHTNING TALKS
KOUJI MATSUI (@KEKYO2)
Kouji Matsui - kekyo
• NAGOYA city, AICHI pref., JP
• Twitter – @kekyo2 / Facebook
• ux-spiral corporation
• Microsoft Most Valuable Professional VS
and DevTech 2015-
• Certified Scrum master / Scrum product
owner
• Center CLR organizer.
• .NET/C#/F#/IL/metaprogramming or like…
• Bike rider
Agenda
Continuation Passing Style
.NET Task / async-await / F# Async workflow
Continuation Linking
Continuation Passing Style
Continuation-passing style (CPS) is a style of programming in which
control is passed explicitly in the form of a continuation.
“continuation-passing style” - Wikipedia
Continuation Passing Style
Continuation function
passing to argument
Continuation implement with
nested lambda expressions…
Standard direct style
Continuation Passing Style (Details)
Continuation-Passing style
Continuation implementation
nearly equals “Callback”
Continuation Passing Style (Details)
The callback technics likely async continuation handler in JavaScript.
Continuation-Passing style
Don’t worry!!
This technics naming “CPS!!”
Continuation Passing Style
Understand CPS?
Agenda
Continuation Passing Style
.NET Task / async-await / F# Async workflow
Continuation Linking
The keyword: .NET Task
The “Task” control interface in .NET 4.0.
In .NET 4.5 with C# 5.0, Task can handle in “async-await” style.
What relationship
between Task and CPS?
.NET Task (In .NET 4.0 / C# 4.0)
.NET 4.0 Task is using with ContinueWith function.
Continuation passing into Task.ContinueWith()
--> likely CPS
.NET Task (In .NET 4.5/C# 5.0)
And in .NET 4.5/C# 5.0 with “async-await” style:
That means
“Continuation” OK?
Using Task with async-await
.NET Task comparison
So, the continuation in async-await:
Means CPS for “async-await” syntax sugar.
In .NET 4.0 (C# 4.0 Task only) And .NET 4.5 (C# 5.0 async-await)
F# Async workflow
Async workflow supported from F# 2.0.
Integrated seamless async handling into F# syntax (In .NET 2.0)
What relationship
between Async and CPS?
F# Async workflow
Structure nearly equals “async-await.”
That’s CPS?
Returned Async<‘T> type
※ let! (Let-Bang) is awaiting for Async<‘T>, and bound ‘T value.
Means C#’s await keyword.
※ If continuation implement in F# Async workflow, use Async.FromContinuations<‘T>.
Overall Async implementations
.NET Task : using ContinueWith
.NET Task : using async-await
F# Async workflow : using let!
Both all patterns nearly with Continuation-Passing style?
Agenda
Continuation Passing Style
.NET Task / async-await / F# Async workflow
Continuation Linking
Connection both continuations
Can I connect by seamless between .NET Tasks and F# Asyncs?
◦ Before thinking, very nearly structure and interfaces for Task<T> and Async<‘T>.
Then?
◦ Can use await in C# for F#’s Async<‘T>?
◦ And/or can use let! in F# async workflow for Task<T>?
◦ If can, use let!, use!, do!, return! handling directly with HttpClient.GetStreamAsync().
Senario for .NET Task / C# side:
Declare augumented function “AsTask” on Async<‘T> class.
Can conversion from Async<‘T> to Task<T>.
◦ Use Async.StartWithContinuations<T> function:
Manipulate “TaskCompletionSource<T> class” (Handled SetResult,
SetException and SetCanceled functions) and returns Task<T>.
Implements Async<‘T>.GetAwaiter function (Augumented).
◦ Can directly awaitable for Async<‘T> in C#.
Senario for .NET Task / C# side:
Can directly awaitable for Async<int>.
C# compiler invoking GetAwaiter function.
Senario for F# Async workflow side:
Declare augumented function “AsAsync” on Task<T> class.
Can conversion from Task<T> to Async<‘T>.
◦ Use Async.FromContinuations<T> function:
Manipulate Async<‘T> functions from Task.ContinueWith function’s callbacks.
And declare augumented function “Source” on AsyncBuilder<‘T> class.
◦ Source function argument is “Task<T>” type and convet to Async<‘T>,
then can use directly let!, use!, do! and return! for Task<T> in F# Async workflow.
Senario for F# Async workflow side:
Can directly awaiting for Task<int>.
F# compiler translate calling “Source” function.
Other tips:
Conversion both System.Void and FSharp.Unit in type-safer:
◦ If awaiting for Async<unit> in C#, cannot receive result value (void).
◦ If using Task (Non-generic) in F# async workflow, can only do! expression.
Support the “CancellationToken”:
◦ .NET Task is explicitly handling CancellationToken (ex: argument received).
F# Async workflow is implicitly handling CancellationToken (Async.DefaultCancellationToken).
◦ --> Add CancellationToken argument for AsTask/AsAsync functions.
Don’t use Async.RunSynchronous function:
◦ If use RunSynchronous function, will be hard-blocked current thread nearly invoking Task.Wait.
Implements using for Async.FromContinuations<‘T> or Async.StartWithContinuations<‘T>.
Implement new type “AsyncCompletionSource<‘T>”:
◦ Async.FromContinuations<T> function handle diffecults (by callback structure) for internal impls.
I want to delegation-based interface likely “TaskCompletionSource<T>” class.
Thanks join!
The implementations --> GitHub: FusionTasks
◦ https://github.com/kekyo/FSharp.Control.FusionTasks
◦ https://www.nuget.org/packages/FSharp.Control.FusionTasks.FS40/
Progressing:
◦ FusionTasks (for .NET Core waiting for F# RTM :) Adjusting PCL profiles :(
◦ fscx (F# expandable compiler project) https://github.com/fscx-projects/
◦ RelaxVersioner (Git based very easy versioner)
https://github.com/kekyo/RelaxVersioner/
My blog (Sorry default language in Japanese)
◦ http://www.kekyo.net/

More Related Content

What's hot

Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)
Leonardo Soto
 
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 'MICROFRONTENDS WITH REACT' by Liliia Karpenko 'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
OdessaJS Conf
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
OdessaJS Conf
 

What's hot (20)

Meetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React TestingMeetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React Testing
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
Code Nomads meetup June 2018 - Angular for Java developers
Code Nomads meetup June 2018 - Angular for Java developersCode Nomads meetup June 2018 - Angular for Java developers
Code Nomads meetup June 2018 - Angular for Java developers
 
J-Spring 2018 - Angular for Java developers
J-Spring 2018 - Angular for Java developersJ-Spring 2018 - Angular for Java developers
J-Spring 2018 - Angular for Java developers
 
OpenValue meetup July 2018 - Angular for Java developers
OpenValue meetup July 2018 - Angular for Java developersOpenValue meetup July 2018 - Angular for Java developers
OpenValue meetup July 2018 - Angular for Java developers
 
Thinking Functionally
Thinking FunctionallyThinking Functionally
Thinking Functionally
 
JSUG - QTJambi by Jan Zarnikov
JSUG - QTJambi by Jan ZarnikovJSUG - QTJambi by Jan Zarnikov
JSUG - QTJambi by Jan Zarnikov
 
Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)Django On Jython (for Portland and Boulder Python user groups presentations)
Django On Jython (for Portland and Boulder Python user groups presentations)
 
Daniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého SchizmaDaniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého Schizma
 
Geb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosperGeb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosper
 
Gdg dev fest 2107 to kotlin, with love
Gdg dev fest 2107   to kotlin, with loveGdg dev fest 2107   to kotlin, with love
Gdg dev fest 2107 to kotlin, with love
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
jQuery (intermediate)
jQuery (intermediate)jQuery (intermediate)
jQuery (intermediate)
 
Branching Strategies: Feature Branches vs Branch by Abstraction
Branching Strategies: Feature Branches vs Branch by AbstractionBranching Strategies: Feature Branches vs Branch by Abstraction
Branching Strategies: Feature Branches vs Branch by Abstraction
 
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 'MICROFRONTENDS WITH REACT' by Liliia Karpenko 'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
 
Nodejs from zero to hero
Nodejs from zero to heroNodejs from zero to hero
Nodejs from zero to hero
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
PHP vs Node.js
PHP vs Node.jsPHP vs Node.js
PHP vs Node.js
 

Viewers also liked

Using Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarUsing Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek Safar
Xamarin
 
Multithreading, Blocking IO and Async IO
Multithreading, Blocking IO and Async IOMultithreading, Blocking IO and Async IO
Multithreading, Blocking IO and Async IO
Directi Group
 
Syncing Async
Syncing AsyncSyncing Async
Syncing Async
FITC
 

Viewers also liked (19)

Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
 
Async and Await on the Server
Async and Await on the ServerAsync and Await on the Server
Async and Await on the Server
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
From Callback Hell to Async Heaven - Promises!
From Callback Hell to Async Heaven - Promises!From Callback Hell to Async Heaven - Promises!
From Callback Hell to Async Heaven - Promises!
 
Sync with async
Sync with  asyncSync with  async
Sync with async
 
Lviv MD Day 2015 Олексій Демедецький "Using Future for async flow application...
Lviv MD Day 2015 Олексій Демедецький "Using Future for async flow application...Lviv MD Day 2015 Олексій Демедецький "Using Future for async flow application...
Lviv MD Day 2015 Олексій Демедецький "Using Future for async flow application...
 
Promises And Chaining In AngularJS - Into Callback Hell And Back Again
Promises And Chaining In AngularJS - Into Callback Hell And Back AgainPromises And Chaining In AngularJS - Into Callback Hell And Back Again
Promises And Chaining In AngularJS - Into Callback Hell And Back Again
 
Using Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek SafarUsing Async in your Mobile Apps - Marek Safar
Using Async in your Mobile Apps - Marek Safar
 
Multithreading, Blocking IO and Async IO
Multithreading, Blocking IO and Async IOMultithreading, Blocking IO and Async IO
Multithreading, Blocking IO and Async IO
 
Async await...oh wait!
Async await...oh wait!Async await...oh wait!
Async await...oh wait!
 
Final LINQ Extensions II
Final LINQ Extensions IIFinal LINQ Extensions II
Final LINQ Extensions II
 
Final LINQ Extensions
Final LINQ ExtensionsFinal LINQ Extensions
Final LINQ Extensions
 
Final LINQ extensions III
Final LINQ extensions IIIFinal LINQ extensions III
Final LINQ extensions III
 
LINQ基本のキ
LINQ基本のキLINQ基本のキ
LINQ基本のキ
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/O
 
Sync async-blocking-nonblocking-io
Sync async-blocking-nonblocking-ioSync async-blocking-nonblocking-io
Sync async-blocking-nonblocking-io
 
Beachhead implements new opcode on CLR JIT
Beachhead implements new opcode on CLR JITBeachhead implements new opcode on CLR JIT
Beachhead implements new opcode on CLR JIT
 
Think Async in Java 8
Think Async in Java 8Think Async in Java 8
Think Async in Java 8
 
Syncing Async
Syncing AsyncSyncing Async
Syncing Async
 

Similar to How to meets Async and Task

The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
Async CTP 3 Presentation for MUGH 2012
Async CTP 3 Presentation for MUGH 2012Async CTP 3 Presentation for MUGH 2012
Async CTP 3 Presentation for MUGH 2012
Sri Kanth
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro
 

Similar to How to meets Async and Task (20)

Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctp
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
Async Await for Mobile Apps
Async Await for Mobile AppsAsync Await for Mobile Apps
Async Await for Mobile Apps
 
CSharp 5 Async
CSharp 5 AsyncCSharp 5 Async
CSharp 5 Async
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
 
Asynchronous Programming in .NET
Asynchronous Programming in .NETAsynchronous Programming in .NET
Asynchronous Programming in .NET
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinC# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
 
F# and SignalR for a FastWeb
F# and SignalR for a FastWebF# and SignalR for a FastWeb
F# and SignalR for a FastWeb
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)
 
Async CTP 3 Presentation for MUGH 2012
Async CTP 3 Presentation for MUGH 2012Async CTP 3 Presentation for MUGH 2012
Async CTP 3 Presentation for MUGH 2012
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
 
Asynchronous Programming.pptx
Asynchronous Programming.pptxAsynchronous Programming.pptx
Asynchronous Programming.pptx
 
Putting the F in FaaS: Functional Compositional Patterns in a Serverless World
Putting the F in FaaS: Functional Compositional Patterns in a Serverless WorldPutting the F in FaaS: Functional Compositional Patterns in a Serverless World
Putting the F in FaaS: Functional Compositional Patterns in a Serverless World
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable Functions
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentation
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Mobile Application Development class 008
Mobile Application Development class 008Mobile Application Development class 008
Mobile Application Development class 008
 

More from Kouji Matsui

More from Kouji Matsui (20)

パターンでわかる! .NET Coreの非同期処理
パターンでわかる! .NET Coreの非同期処理パターンでわかる! .NET Coreの非同期処理
パターンでわかる! .NET Coreの非同期処理
 
Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018
 
Matrix signal controller and BrainPad overview
Matrix signal controller and BrainPad overviewMatrix signal controller and BrainPad overview
Matrix signal controller and BrainPad overview
 
Fun with BrainPad
Fun with BrainPadFun with BrainPad
Fun with BrainPad
 
What's Functional?
What's Functional?What's Functional?
What's Functional?
 
Pitfall for WioLTE
Pitfall for WioLTEPitfall for WioLTE
Pitfall for WioLTE
 
How to make the calculator
How to make the calculatorHow to make the calculator
How to make the calculator
 
Write common, run anywhere
Write common, run anywhereWrite common, run anywhere
Write common, run anywhere
 
Locality of Reference
Locality of ReferenceLocality of Reference
Locality of Reference
 
Nespのコード生成
Nespのコード生成Nespのコード生成
Nespのコード生成
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonad
 
You will be assimilated. Resistance is futile.
You will be assimilated. Resistance is futile.You will be assimilated. Resistance is futile.
You will be assimilated. Resistance is futile.
 
Async deepdive before de:code
Async deepdive before de:codeAsync deepdive before de:code
Async deepdive before de:code
 
Thread affinity and CPS
Thread affinity and CPSThread affinity and CPS
Thread affinity and CPS
 
Async DeepDive basics
Async DeepDive basicsAsync DeepDive basics
Async DeepDive basics
 
continuatioN Linking
continuatioN LinkingcontinuatioN Linking
continuatioN Linking
 
真Intermediate languageのキホン
真Intermediate languageのキホン真Intermediate languageのキホン
真Intermediate languageのキホン
 
.NET Coreから概観する.NETのOSSへの取り組み
.NET Coreから概観する.NETのOSSへの取り組み.NET Coreから概観する.NETのOSSへの取り組み
.NET Coreから概観する.NETのOSSへの取り組み
 
Win32 APIをてなずけよう
Win32 APIをてなずけようWin32 APIをてなずけよう
Win32 APIをてなずけよう
 
式の体を成して無い式を式の体を成すように式と式木で何とかする式
式の体を成して無い式を式の体を成すように式と式木で何とかする式式の体を成して無い式を式の体を成すように式と式木で何とかする式
式の体を成して無い式を式の体を成すように式と式木で何とかする式
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

How to meets Async and Task

  • 1. How to meets Async and Task 2016.11.08 MVP SUMMIT SPECIAL: A NIGHT OF LIGHTNING TALKS KOUJI MATSUI (@KEKYO2)
  • 2. Kouji Matsui - kekyo • NAGOYA city, AICHI pref., JP • Twitter – @kekyo2 / Facebook • ux-spiral corporation • Microsoft Most Valuable Professional VS and DevTech 2015- • Certified Scrum master / Scrum product owner • Center CLR organizer. • .NET/C#/F#/IL/metaprogramming or like… • Bike rider
  • 3. Agenda Continuation Passing Style .NET Task / async-await / F# Async workflow Continuation Linking
  • 4. Continuation Passing Style Continuation-passing style (CPS) is a style of programming in which control is passed explicitly in the form of a continuation. “continuation-passing style” - Wikipedia
  • 5. Continuation Passing Style Continuation function passing to argument Continuation implement with nested lambda expressions… Standard direct style
  • 6. Continuation Passing Style (Details) Continuation-Passing style Continuation implementation nearly equals “Callback”
  • 7. Continuation Passing Style (Details) The callback technics likely async continuation handler in JavaScript. Continuation-Passing style Don’t worry!! This technics naming “CPS!!”
  • 9. Agenda Continuation Passing Style .NET Task / async-await / F# Async workflow Continuation Linking
  • 10. The keyword: .NET Task The “Task” control interface in .NET 4.0. In .NET 4.5 with C# 5.0, Task can handle in “async-await” style. What relationship between Task and CPS?
  • 11. .NET Task (In .NET 4.0 / C# 4.0) .NET 4.0 Task is using with ContinueWith function. Continuation passing into Task.ContinueWith() --> likely CPS
  • 12. .NET Task (In .NET 4.5/C# 5.0) And in .NET 4.5/C# 5.0 with “async-await” style: That means “Continuation” OK? Using Task with async-await
  • 13. .NET Task comparison So, the continuation in async-await: Means CPS for “async-await” syntax sugar. In .NET 4.0 (C# 4.0 Task only) And .NET 4.5 (C# 5.0 async-await)
  • 14. F# Async workflow Async workflow supported from F# 2.0. Integrated seamless async handling into F# syntax (In .NET 2.0) What relationship between Async and CPS?
  • 15. F# Async workflow Structure nearly equals “async-await.” That’s CPS? Returned Async<‘T> type ※ let! (Let-Bang) is awaiting for Async<‘T>, and bound ‘T value. Means C#’s await keyword. ※ If continuation implement in F# Async workflow, use Async.FromContinuations<‘T>.
  • 16. Overall Async implementations .NET Task : using ContinueWith .NET Task : using async-await F# Async workflow : using let! Both all patterns nearly with Continuation-Passing style?
  • 17. Agenda Continuation Passing Style .NET Task / async-await / F# Async workflow Continuation Linking
  • 18. Connection both continuations Can I connect by seamless between .NET Tasks and F# Asyncs? ◦ Before thinking, very nearly structure and interfaces for Task<T> and Async<‘T>. Then? ◦ Can use await in C# for F#’s Async<‘T>? ◦ And/or can use let! in F# async workflow for Task<T>? ◦ If can, use let!, use!, do!, return! handling directly with HttpClient.GetStreamAsync().
  • 19. Senario for .NET Task / C# side: Declare augumented function “AsTask” on Async<‘T> class. Can conversion from Async<‘T> to Task<T>. ◦ Use Async.StartWithContinuations<T> function: Manipulate “TaskCompletionSource<T> class” (Handled SetResult, SetException and SetCanceled functions) and returns Task<T>. Implements Async<‘T>.GetAwaiter function (Augumented). ◦ Can directly awaitable for Async<‘T> in C#.
  • 20. Senario for .NET Task / C# side: Can directly awaitable for Async<int>. C# compiler invoking GetAwaiter function.
  • 21. Senario for F# Async workflow side: Declare augumented function “AsAsync” on Task<T> class. Can conversion from Task<T> to Async<‘T>. ◦ Use Async.FromContinuations<T> function: Manipulate Async<‘T> functions from Task.ContinueWith function’s callbacks. And declare augumented function “Source” on AsyncBuilder<‘T> class. ◦ Source function argument is “Task<T>” type and convet to Async<‘T>, then can use directly let!, use!, do! and return! for Task<T> in F# Async workflow.
  • 22. Senario for F# Async workflow side: Can directly awaiting for Task<int>. F# compiler translate calling “Source” function.
  • 23. Other tips: Conversion both System.Void and FSharp.Unit in type-safer: ◦ If awaiting for Async<unit> in C#, cannot receive result value (void). ◦ If using Task (Non-generic) in F# async workflow, can only do! expression. Support the “CancellationToken”: ◦ .NET Task is explicitly handling CancellationToken (ex: argument received). F# Async workflow is implicitly handling CancellationToken (Async.DefaultCancellationToken). ◦ --> Add CancellationToken argument for AsTask/AsAsync functions. Don’t use Async.RunSynchronous function: ◦ If use RunSynchronous function, will be hard-blocked current thread nearly invoking Task.Wait. Implements using for Async.FromContinuations<‘T> or Async.StartWithContinuations<‘T>. Implement new type “AsyncCompletionSource<‘T>”: ◦ Async.FromContinuations<T> function handle diffecults (by callback structure) for internal impls. I want to delegation-based interface likely “TaskCompletionSource<T>” class.
  • 24. Thanks join! The implementations --> GitHub: FusionTasks ◦ https://github.com/kekyo/FSharp.Control.FusionTasks ◦ https://www.nuget.org/packages/FSharp.Control.FusionTasks.FS40/ Progressing: ◦ FusionTasks (for .NET Core waiting for F# RTM :) Adjusting PCL profiles :( ◦ fscx (F# expandable compiler project) https://github.com/fscx-projects/ ◦ RelaxVersioner (Git based very easy versioner) https://github.com/kekyo/RelaxVersioner/ My blog (Sorry default language in Japanese) ◦ http://www.kekyo.net/