SlideShare a Scribd company logo
1 of 20
Download to read offline
Bolts
Superbil @Cocoaheads Taipei
About me
• 燒毀果蠅的蘋果園藝師
• Objective-C / Git / Emacs / Python
• about.me/superbil , @superbil
• freenode #g0v.tw #emacs.tw
• Freelance Software Developer
Guideline
• Functional Reactive Programming
• Bolts Intro
• Why Bolts?
• Example
Functional Reactive Programming
• 讓資料流變化可以⾃自動傳播的程式設計典範
FRP與函數式 http://www.ithome.com.tw/voice/91328
Why Bolts ?
• Facebook
• github.com/zonble/CWBOpenDataClient
Why Bolts?
• NSRunloop
• input source
• Timer sources
mikeash NSRunLoop Internals https://mikeash.com/pyblog/friday-qa-2010-01-01-nsrunloop-internals.html
Bolts Intro
• A task is kind of like a JavaScript Promise
https://www.promisejs.org/
Bolts Intro
• Property: data sequence than remembers only
the last value
• a property with only one single value/event
• Promises are a subset of FRP
Taming Asynchronous Programming (beyond Promises) 

http://eamodeorubio.github.io/tamingasync/#/60
Promise
• must have value (callback)
• result
• error
• etc..
contiuneWithBlock:
[[self saveAsync:obj] continueWithBlock:^id(BFTask
*task) {
if (task.isCancelled) {
// the save was cancelled.
} else if (task.error) {
// the save failed.
} else {
// the object was saved successfully.
PFObject *object = task.result;
}
return nil;
}];
continueWithExecutor:withBlock:
// Continue on the Main Thread, using a built-in executor.
[[self fetchAsync:object]
continueWithExecutor:[BFExecutor mainThreadExecutor]
withBlock:^id(BFTask *task) {
myTextView.text = [object objectForKey:@"name"];
}];
nil is end
[[self saveAsync:obj]
continueWithSuccessBlock:^id(BFTask *task) {
// the object was saved successfully.
return nil;
}];
BFTaskCompletionSource
• Normal use
• setResult:
• setError:
• setException:
• cancel
• Try to set
• trySetResult
• trySetError
• trySetException
• trySetCancelled
BFExecutor
• defaultExecutor
• mainThreadExecutor
• dispatch_queue_t
• NSOperationQueue
for completion
• taskForCompletionOfAllTasks:
• taskForCompletionOfAllTasksWithResults:
BFCancellationToken
• Solve flow need cancel problem
• After 1.2.0 support
BFCancellationToken
BFCancellationTokenSource *cts =
[BFCancellationTokenSource cancellationTokenSource];
[cts.token registerCancellationObserverWithBlock:^{
NSLog(@"A");
}];
BFTask *task = [BFTask taskWithDelay:500];
[task continueWithBlock:^id(BFTask *task) {
NSLog(@"B");
return nil;
} cancellationToken:cts.token];
NSLog(@“C");
[cts cancel];
Live DEMO
More example
• https://github.com/BoltsFramework/Bolts-iOS
• Readme.md
• TaskTests.m
• CancellationTests.m
Q & A

More Related Content

What's hot

eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
PatrickCrompton
 

What's hot (20)

Kamailio :: A Quick Introduction
Kamailio :: A Quick IntroductionKamailio :: A Quick Introduction
Kamailio :: A Quick Introduction
 
轉轉轉好運旺來一起來之雲端轉檔大作戰!
轉轉轉好運旺來一起來之雲端轉檔大作戰!轉轉轉好運旺來一起來之雲端轉檔大作戰!
轉轉轉好運旺來一起來之雲端轉檔大作戰!
 
Capybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCapybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automation
 
Opslogger: Operations code (should be) production quality too!
Opslogger: Operations code (should be) production quality too!Opslogger: Operations code (should be) production quality too!
Opslogger: Operations code (should be) production quality too!
 
Kamailio - SIP Routing in Lua
Kamailio - SIP Routing in LuaKamailio - SIP Routing in Lua
Kamailio - SIP Routing in Lua
 
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
 
Applying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScriptApplying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScript
 
Big Data DC - BenchPress
Big Data DC - BenchPressBig Data DC - BenchPress
Big Data DC - BenchPress
 
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
 
Ansible Best Practices - July 30
Ansible Best Practices - July 30Ansible Best Practices - July 30
Ansible Best Practices - July 30
 
Sergei Nesterov "How to Speed Up the Build of Large Projects. Overview and C...
Sergei Nesterov  "How to Speed Up the Build of Large Projects. Overview and C...Sergei Nesterov  "How to Speed Up the Build of Large Projects. Overview and C...
Sergei Nesterov "How to Speed Up the Build of Large Projects. Overview and C...
 
Pharo VM Performance
Pharo VM PerformancePharo VM Performance
Pharo VM Performance
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
Kamailio - Unifying SIP and Web Worlds with Lua
Kamailio - Unifying SIP and Web Worlds with LuaKamailio - Unifying SIP and Web Worlds with Lua
Kamailio - Unifying SIP and Web Worlds with Lua
 
What is (not) Pharo 8?
What is (not) Pharo 8?What is (not) Pharo 8?
What is (not) Pharo 8?
 
Infrastructre as Ccodeの実現 - Ansibleの基本 -
Infrastructre as Ccodeの実現 - Ansibleの基本 - Infrastructre as Ccodeの実現 - Ansibleの基本 -
Infrastructre as Ccodeの実現 - Ansibleの基本 -
 
KazooCon 2014 - WebRTC
KazooCon 2014 - WebRTCKazooCon 2014 - WebRTC
KazooCon 2014 - WebRTC
 
Brewing ALE with Pi
Brewing ALE with PiBrewing ALE with Pi
Brewing ALE with Pi
 
Parsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby TemplatesParsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby Templates
 

Similar to Bolts

Python to go
Python to goPython to go
Python to go
Weng Wei
 

Similar to Bolts (20)

貢獻開源專案 (Contribute to open source project)
貢獻開源專案 (Contribute to open source project)貢獻開源專案 (Contribute to open source project)
貢獻開源專案 (Contribute to open source project)
 
Qcon beijing 2010
Qcon beijing 2010Qcon beijing 2010
Qcon beijing 2010
 
ModernWeb 2019: Why we replace TypeScript with Dart
ModernWeb 2019: Why we replace TypeScript with DartModernWeb 2019: Why we replace TypeScript with Dart
ModernWeb 2019: Why we replace TypeScript with Dart
 
Spock testing
Spock testingSpock testing
Spock testing
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
 
デザインシステムの海で3年間もがいてみて
デザインシステムの海で3年間もがいてみてデザインシステムの海で3年間もがいてみて
デザインシステムの海で3年間もがいてみて
 
Python to go
Python to goPython to go
Python to go
 
Why I Love TorqueBox (And Why You Will Too)
Why I Love TorqueBox (And Why You Will Too)Why I Love TorqueBox (And Why You Will Too)
Why I Love TorqueBox (And Why You Will Too)
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
 
Developing Brilliant and Powerful APIs in Ruby & Python
Developing Brilliant and Powerful APIs in Ruby & PythonDeveloping Brilliant and Powerful APIs in Ruby & Python
Developing Brilliant and Powerful APIs in Ruby & Python
 
Contributing to rails
Contributing to railsContributing to rails
Contributing to rails
 
Stackato v4
Stackato v4Stackato v4
Stackato v4
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Angular Day 2018 (italy) - Keynote - The Amazing World of Angular 6
Angular Day 2018 (italy) - Keynote - The Amazing World of Angular 6Angular Day 2018 (italy) - Keynote - The Amazing World of Angular 6
Angular Day 2018 (italy) - Keynote - The Amazing World of Angular 6
 
Project Based Learning using by PaaS
Project Based Learning using by PaaSProject Based Learning using by PaaS
Project Based Learning using by PaaS
 
Putting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctionsPutting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctions
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Integration Testing Practice using Perl
Integration Testing Practice using PerlIntegration Testing Practice using Perl
Integration Testing Practice using Perl
 
PyCon Ukraine 2014
PyCon Ukraine 2014PyCon Ukraine 2014
PyCon Ukraine 2014
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Bolts