SlideShare a Scribd company logo
Alexander Khokhlov
@nots_ioNots.io
— Knock, knock
— An async template
— Who’s there?
Co-Founder
Nots.io
01
 — Knock, knock — An async templates — Who’s there? - Alexander Khokhlov  |  Elixir Club 13
 — Knock, knock — An async templates — Who’s there? - Alexander Khokhlov  |  Elixir Club 13
 — Knock, knock — An async templates — Who’s there? - Alexander Khokhlov  |  Elixir Club 13
 — Knock, knock — An async templates — Who’s there? - Alexander Khokhlov  |  Elixir Club 13
README.md
Code Comments
JavaDoc
GDocs
Confluence / DokuWiki / Wiki
Nots.io
Add docs for block of code,
function, module, file,
commit or branch
01
Notes, Tied
to Code
Easy to Discover
Easy to Explore
Easy to Get Scope
Easy to Ask and Discuss
01 • Nots.io
We Track
Relevance
You always know what’s fresh
and what’s not.
Promotes keeping docs
up-to-date.
Rewarding when everything is ✅
01 • Nots.io
Discuss with
your Team
You won’t loose a dispute
that is written down.
It’s tied and has context
01 • Nots.io
And many more
awesome things
🔥
01 • Nots.io
Nots.io case
02
🏗
Choose File
page
02 • Nots.io case
02 • Nots.io case
In the
template
02 • Nots.io case
.branch-selector
= Notsapp.Renderer.simple_component({:"dropdown/dropdown", …})
%h2 Files
.tree
= Notsapp.Renderer.simple_component({:"code-tree/tree", …})
Microservices
YAY!
02 • Nots.io case
⛔
⛔
Blocking
04
.branch-selector
= Notsapp.Renderer.simple_component({:"dropdown/dropdown", …})
%h2 Files
.tree
= Notsapp.Renderer.simple_component({:"code-tree/tree", …})
But we want non-blocking
02
🚀
Good news: It’s doable!
02
But first
03
03
Phoenix
templates
But first
iolist() | iodata()
03 • Phoenix templates
IO.puts(["Hello, ", "Elixir"])
IO.puts ["Hello, ", 69, 108, 105, 120,
105, 114]
IO.puts ["Hello, ", [69, [108, [105,
[120, [105, [114, ]]]]]]]
But first
iolist() | iodata()
Does not allocate new strings: Repeated
chunks are created only once
Does not concatenate strings/chars: Append
to the list is O(1) and doesn’t require copying
anything.
03 • Phoenix templates
Use iolist for I/O
iolist() | iodata()
With iolist & iodata work:
Console I/O functions
File I/O function
:gen_tcp.send()
:gen_udp.send()
03 • Phoenix templates
What about Elixir
& Phoenix?
03 • Phoenix templates
At compile time Phoenix runs through the templates folder
Uses EEx to convert each template into a
function
phoenix/lib/phoenix/template.ex
03 • Phoenix templates
At compile time
https://www.bignerdranch.com/blog/elixir-and-io-lists-part-2-io-lists-in-phoenix/
03 • Phoenix templates
At compile time
03 • Phoenix templates
At compile time
https://www.bignerdranch.com/blog/elixir-and-io-lists-part-2-io-lists-in-phoenix/
03 • Phoenix templates
At compile time
https://www.bignerdranch.com/blog/elixir-and-io-lists-part-2-io-lists-in-phoenix/
03 • Phoenix templates
defmodule MyApp.SomeView do
defp(index.html(var!(assigns))) do
_ = var!(assigns)
{:safe, [(
tmp1 = ["" | "<h1>Listing Users</h1>nn<ul>n "]
[tmp1 | case(for(user <- Phoenix.HTML.Engine.fetch_assign(var!(assigns), :users)) do
{:safe, [(
tmp1 = [(
tmp1 = ["" | "n <li> “]
[tmp1 | case(user.first_name()) do
{:safe, data} ->
data
bin when is_binary(bin) ->
Plug.HTML.html_escape(bin)
other ->
Phoenix.HTML.Safe.to_iodata(other)
end]
) | " (“]
…
| "n</ul>nnThat's all!n"]}
Gosh!
03 • Phoenix templates
At the end
of the day {:safe, [[["" | "<h1>Listing Users</h1>nn<ul>n "],
[[[[["" | "n <li>"] | "Jane"] | " ("] | "1"] | ")</li>n "],
[[[[["" | "n <li>"] | "Joe"] | " ("] | "2"] | ")</li>n "]] |
"n</ul>nnThat's all!n"]}
iolist
In runtime
03 • Phoenix templates
Rewind ⏪
04
.branch-selector
= Notsapp.Renderer.simple_component({:"dropdown/dropdown", …})
%h2 Files
.tree
= Notsapp.Renderer.simple_component({:"code-tree/tree", …})
What if we
return Task 🤔
Instead of HTML
04 • The solution
task = Task.async(fn -> do_heavy_work() end)
IO.puts "Do some more work"
result = Task.await(task)
What if we
return Task 🤔
in pseudocode
04 • The solution
{:safe, [["" | "<div class="branch-selector"""> "],
["" | Task.async(fn -> render_dropdown() end)] ,
["" | "n</div>nn"]]}
And when
everything is
ready — convert
04 • The solution
defmodule Notsapp.TemplateRenderer do
def process_rendered_template([h|t]) do
[process_rendered_template(h) | process_rendered_template(t)]
end
def process_rendered_template(%Notsapp.CljTask{task: task}) do
Task.await(task)
end
def process_rendered_template(e) do
e
end
defmacro __using__(_opts) do
quote do
def render(template, assigns) do
{:safe, io_list} = render_template(template, assigns)
{:safe, process_rendered_template(io_list)}
end
end
end
end
Apply to
every view
04 • The solution
def view do
quote do
use Phoenix.View
use Notsapp.TemplateRenderer # <--
use Phoenix.HTML
In parallel
Thank you
🤘
Alexander Khokhlov
point@nots.io
Nots.io
nots.io
blog.nots.io
@nots_io
facebook.com/nots.io

More Related Content

PDF
Useful Shareware / Freeware for Technical Communicators
PPTX
02 beginning code first
PPTX
CamSec Sept 2016 - Tricks to improve web app excel export attacks
PDF
OCCIware
PDF
Doing Drupal security right
PDF
Introduction to Solr
PPTX
Beyond Comments: How to Build an Awesome API Doc and Be a Better Person
PPT
Useful Shareware / Freeware for Technical Communicators
02 beginning code first
CamSec Sept 2016 - Tricks to improve web app excel export attacks
OCCIware
Doing Drupal security right
Introduction to Solr
Beyond Comments: How to Build an Awesome API Doc and Be a Better Person

What's hot (20)

PDF
Owasp tds
PPTX
20130310 solr tuorial
PPTX
Introduction to Apache Solr
PPTX
Battle of the giants: Apache Solr vs ElasticSearch
PDF
Rebuilding Solr 6 Examples - Layer by Layer: Presented by Alexandre Rafalovit...
PDF
Intro to Apache Solr
PPTX
VB2013 - Security Research and Development Framework
PDF
Apache Solr crash course
PPTX
Black Hat: XML Out-Of-Band Data Retrieval
PDF
Introduction to Apache Solr
PPTX
Node.js: The What, The How and The When
PPTX
Introduction to Lucene and Solr - 1
PDF
Firebird Interbase Database engine hacks or rtfm
PPTX
Hacking Lucene for Custom Search Results
KEY
State-of-the-Art Drupal Search with Apache Solr
PPTX
Why I love Elixir by Jukka Välimaa from Elixir Meetup 2/2020
PDF
Solr Recipes
PDF
Solr 4
PPTX
Apache Solr
PPT
Domino testing presentation
Owasp tds
20130310 solr tuorial
Introduction to Apache Solr
Battle of the giants: Apache Solr vs ElasticSearch
Rebuilding Solr 6 Examples - Layer by Layer: Presented by Alexandre Rafalovit...
Intro to Apache Solr
VB2013 - Security Research and Development Framework
Apache Solr crash course
Black Hat: XML Out-Of-Band Data Retrieval
Introduction to Apache Solr
Node.js: The What, The How and The When
Introduction to Lucene and Solr - 1
Firebird Interbase Database engine hacks or rtfm
Hacking Lucene for Custom Search Results
State-of-the-Art Drupal Search with Apache Solr
Why I love Elixir by Jukka Välimaa from Elixir Meetup 2/2020
Solr Recipes
Solr 4
Apache Solr
Domino testing presentation
Ad

Similar to — Knock, knock — An async templates — Who’s there? - Alexander Khokhlov | Elixir Club 13 (20)

PDF
— An async template - Oleksandr Khokhlov | Elixir Club Ukraine
PPTX
Python and Oracle : allies for best of data management
PDF
COMMitMDE'18: Eclipse Hawk: model repository querying as a service
PPTX
[DanNotes] XPages - Beyound the Basics
PPTX
Protect Your Payloads: Modern Keying Techniques
PDF
Lares from LOW to PWNED
PDF
Devry CIS 246 Full Course Latest
PPT
Domino testing presentation
PPT
XPages -Beyond the Basics
PDF
C++ Windows Forms L01 - Intro
PDF
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
PDF
Oracle forensics 101
PDF
Fix me if you can - DrupalCon prague
PDF
Accelerating Data Ingestion with Databricks Autoloader
PDF
ITB 2023 Creating and managing a QA focused production-replicating environmen...
PPT
Extension Library - Viagra for XPages
PPTX
On non existent 0-days, stable binary exploits and
PDF
Esage on non-existent 0-days, stable binary exploits and user interaction
PPSX
Open writing-cloud-collab
PPTX
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
— An async template - Oleksandr Khokhlov | Elixir Club Ukraine
Python and Oracle : allies for best of data management
COMMitMDE'18: Eclipse Hawk: model repository querying as a service
[DanNotes] XPages - Beyound the Basics
Protect Your Payloads: Modern Keying Techniques
Lares from LOW to PWNED
Devry CIS 246 Full Course Latest
Domino testing presentation
XPages -Beyond the Basics
C++ Windows Forms L01 - Intro
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Oracle forensics 101
Fix me if you can - DrupalCon prague
Accelerating Data Ingestion with Databricks Autoloader
ITB 2023 Creating and managing a QA focused production-replicating environmen...
Extension Library - Viagra for XPages
On non existent 0-days, stable binary exploits and
Esage on non-existent 0-days, stable binary exploits and user interaction
Open writing-cloud-collab
Open Writing! Collaborative Authoring for CloudStack Documentation by Jessica...
Ad

More from Elixir Club (20)

PDF
Kubernetes + Docker + Elixir - Alexei Sholik, Andrew Dryga | Elixir Club Ukraine
PDF
Integrating 3rd parties with Ecto - Eduardo Aguilera | Elixir Club Ukraine
PDF
BEAM architecture handbook - Andrea Leopardi | Elixir Club Ukraine
PDF
You ain't gonna need write a GenServer - Ulisses Almeida | Elixir Club Ukraine
PDF
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
PDF
Erlang cluster. How is it? Production experience. — Valerii Vasylkov | Elixi...
PDF
Promo Phx4RailsDevs - Volodya Sveredyuk
PDF
Web of today — Alexander Khokhlov
PDF
ElixirConf Eu 2018, what was it like? – Eugene Pirogov
PDF
Implementing GraphQL API in Elixir – Victor Deryagin
PDF
WebPerformance: Why and How? – Stefan Wintermeyer
PDF
GenServer in Action – Yurii Bodarev
PDF
Russian Doll Paradox: Elixir Web without Phoenix - Alex Rozumii
PDF
Practical Fault Tolerance in Elixir - Alexei Sholik
PDF
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
PDF
Monads are just monoids in the category of endofunctors - Ike Kurghinyan
PDF
Craft effective API with GraphQL and Absinthe - Ihor Katkov
PDF
Elixir in a service of government - Alex Troush
PDF
Pattern matching in Elixir by example - Alexander Khokhlov
PDF
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev
Kubernetes + Docker + Elixir - Alexei Sholik, Andrew Dryga | Elixir Club Ukraine
Integrating 3rd parties with Ecto - Eduardo Aguilera | Elixir Club Ukraine
BEAM architecture handbook - Andrea Leopardi | Elixir Club Ukraine
You ain't gonna need write a GenServer - Ulisses Almeida | Elixir Club Ukraine
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Erlang cluster. How is it? Production experience. — Valerii Vasylkov | Elixi...
Promo Phx4RailsDevs - Volodya Sveredyuk
Web of today — Alexander Khokhlov
ElixirConf Eu 2018, what was it like? – Eugene Pirogov
Implementing GraphQL API in Elixir – Victor Deryagin
WebPerformance: Why and How? – Stefan Wintermeyer
GenServer in Action – Yurii Bodarev
Russian Doll Paradox: Elixir Web without Phoenix - Alex Rozumii
Practical Fault Tolerance in Elixir - Alexei Sholik
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
Monads are just monoids in the category of endofunctors - Ike Kurghinyan
Craft effective API with GraphQL and Absinthe - Ihor Katkov
Elixir in a service of government - Alex Troush
Pattern matching in Elixir by example - Alexander Khokhlov
Ecto and Phoenix: Doing web with Elixir - Yurii Bodarev

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
PDF
Getting Started with Data Integration: FME Form 101
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Spectral efficient network and resource selection model in 5G networks
A comparative analysis of optical character recognition models for extracting...
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Assigned Numbers - 2025 - Bluetooth® Document
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
Getting Started with Data Integration: FME Form 101

— Knock, knock — An async templates — Who’s there? - Alexander Khokhlov | Elixir Club 13