SlideShare ist ein Scribd-Unternehmen logo
1 von 34
CSP: Huh? And Components
@TheHydroImpulse
hydrocodedesign.com
github.com/TheHydroImpulse
Communicating Sequential Processes
•

I won’t be getting into the complex theory.

•

I’ll be going into the practical examples of CSP.
Concurrency
What is it exactly?
Concurrency != Parallelism
•
•
•

Concurrency is a model for concurrent
execution.
Parallelism is the literal act of being
concurrent.
With concurrency, tasks are able to run at the same
time,
but they don’t have to — that’s
parallelism.
CSP: Huh?
•

A formal language for describing patterns of
interaction in concurrent systems.

•

based on message passing via channels.
Channels
•

A powerful primitive for communication

•

Channels are exactly what you think it is; they let you pass stuff
through it.

•

Two basic actions: Put & Take

Input

Channel

Output
Kinds of Channels
Buffered
Unbuffered (Can be dangerous)
Basic Actions
•

Put: Send a new value onto the channel

•

Take: Receive on existing value from the channel.
Channel Semantics
•

Semantics vary on the language/implementation.

•

The basic semantics are:
•

on share-ability of concrete channels. (i.e., across
tasks/threads?)

•

when channels block
Blocking
•

Can block when trying to put a value onto the
channel when it’s full.

•

Can block when trying to take a value from an
empty channel.
What Blocks?
•

Very much dependent on the implementation/language.
•

Golang blocks on goroutines (a.k.a green threads)

•

Rust blocks on tasks (a.k.a green threads or native
threads)

•

Clojure (core.async): both actions have the potential
to block the underlying thread.
Clojure: core.async
•

A library not a language feature.

•

Goes to show how powerful a consistent language form (Lisp)
can be, thanks to macros.

•

Supports unbounded buffered and bounded buffered
channels. The former is discouraged.

•

Two implementations of the underlying “threads”.

•

Supports timeouts (super powerful)

•

All operations are expressions not statements.

•

Priority selects with alts!
Clojure: core.async
•

Supports two kinds of thread of control:
•
•

•

IoC (inversion of control)
Normal Threads

IoC threads are created with go blocks
•

go is a macro that examines it’s body for any
channel operations and turns them into a state
machine.

•

C#’s async does the same thing.
Clojure: Example!
JavaScript Example!
•

Uses ES6 Generators

•

Similar to ClojureScript/Clojure’s go blocks.
Callbacks (Direct Data-Flow)
•

Worst style of concurrency

•

You have no control over the data flow.

•

You’re (the callback) at the mercy of the caller.
Direct vs Indirect
Direc
t
In

Callback/Logic

Out

Indirec
t
In

Channel

Logic

Channel

Out
Indirect = Channels
•

Channels offer a better alternative at managing
data-flow.

•

They are indirect. This means the logic is in control
of the data-flow.

•

The logic can decide when it’s had too much data
coming through. It’s the best decider at judging how
much it can handle.
Examples!
•

Return the 5 fastest search queries.

•

Return the x number of queries that finish within 3
seconds (timeouts)

•

Channels act like queues. They’re a buffer for your
data.
Components
Building modular applications.
Components
•

Not an abstract component.

•

https://github.com/component/component

•

A client-side package manager and build tool.

•

CommonJS style code.

•

Ability to share client and server code super easily.
Unix Style
•

Build small, concentrated applications that do one
thing, and does that thing extremely well.

•

Modular

•

Modular

•

Modular
Globals..grrr
•

Globals are horrible. Never use them.

•

Globals are horrible. Never use them.

•

Globals are horrible. Never use them.

•

jQuery, Angular, Ember, etc… ALL use them.
/**
* Module Dependencies
*/
var dom = require('dom');
var model = require('tower-model');
var migration = require('tower-migration');
/**
* User Model
*/
model('user')
.attr('email')
.validate('presence')
.validate('isEmail')
.attr('firstname')
.attr('lastname')
.attr('country')
.attr('city');
/**
* Migration
*/
migration.up('create_user_table')
.model('user');
Creating a Component App
Modular Apps
•

It’s the future

•

Building monolithic apps suck

•

Tooling is only going to get better.

•

It’s much easier to wrap your head around a single
module that has no side-effects (i.e., no external
state & globals).
Server & Client-side
•

Node.js offers the ability to share code with the
client-side (components).

•

Both have the same module pattern (CommonJS

•

Module can now be designed for both platforms.
No Globals?
•

We can take advantage of the module caching.

•

A version of inversion-of-control

•

Decentralized.
Module Caching
•

If each module is concentrated, you can store data (instances,
values, etc…) in the module exports or module itself.

•

Example!
Wrapping Up
•

CSP is awesome.

•

Clojure is awesome.

•

Message passing & channels are awesome.

•

Modular apps are awesome.

•

Globals are horrible.

•

Callbacks are horrible.
Resources
Components & ES6
•

Module system in ES6 replaces the build system in
component.

•

Components might just become a package
manager.
Thanks!
@TheHydroImpuls
e
github.com/TheHydroImpulse
hydrocodedesign.co
m

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor model
 
Web development basics (Part-2)
Web development basics (Part-2)Web development basics (Part-2)
Web development basics (Part-2)
 
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
Actors and Microservices - Can two walk together? - Rotem Hermon, GigyaActors and Microservices - Can two walk together? - Rotem Hermon, Gigya
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
 
Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
 
Coding in kotlin
Coding in kotlinCoding in kotlin
Coding in kotlin
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Akka framework
Akka frameworkAkka framework
Akka framework
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
Introduction to the Actor Model
Introduction to the Actor ModelIntroduction to the Actor Model
Introduction to the Actor Model
 
Metaprogramming with javascript
Metaprogramming with javascriptMetaprogramming with javascript
Metaprogramming with javascript
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 

Andere mochten auch (7)

pastas chinas
pastas chinaspastas chinas
pastas chinas
 
Forecast MSU-IIT
Forecast MSU-IITForecast MSU-IIT
Forecast MSU-IIT
 
Программа #smART
Программа #smARTПрограмма #smART
Программа #smART
 
Cheltenham Festival Free bet
Cheltenham Festival Free betCheltenham Festival Free bet
Cheltenham Festival Free bet
 
The solar system 5.40.40 pm
The solar system 5.40.40 pmThe solar system 5.40.40 pm
The solar system 5.40.40 pm
 
Каталог упаковки компании "Дилявер" 2015 - 2016
Каталог упаковки компании "Дилявер" 2015 - 2016 Каталог упаковки компании "Дилявер" 2015 - 2016
Каталог упаковки компании "Дилявер" 2015 - 2016
 
Decor Stone - Stone Cladding and Paving Stones
Decor Stone - Stone Cladding and Paving StonesDecor Stone - Stone Cladding and Paving Stones
Decor Stone - Stone Cladding and Paving Stones
 

Ähnlich wie CSP: Huh? And Components

Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
Tomas Doran
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
Christophe Grand
 
Solvcon PyCon APAC 2014
Solvcon PyCon APAC 2014Solvcon PyCon APAC 2014
Solvcon PyCon APAC 2014
weijr
 

Ähnlich wie CSP: Huh? And Components (20)

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
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
 
2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon
 
Core JavaScript
Core JavaScriptCore JavaScript
Core JavaScript
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenix
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
 
Starting from scratch in 2017
Starting from scratch in 2017Starting from scratch in 2017
Starting from scratch in 2017
 
Solvcon PyCon APAC 2014
Solvcon PyCon APAC 2014Solvcon PyCon APAC 2014
Solvcon PyCon APAC 2014
 
Actors evolved- Rotem Hermon
Actors evolved- Rotem HermonActors evolved- Rotem Hermon
Actors evolved- Rotem Hermon
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
 
Akka.Net Overview
Akka.Net OverviewAkka.Net Overview
Akka.Net Overview
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingInto the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional Programming
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 

CSP: Huh? And Components

Hinweis der Redaktion

  1. Hello World