A design pattern provides a general reusable solution for the common problems that occur in software design. The pattern typically shows relationships and interactions between classes or objects. The idea is to speed up the development process by providing well-tested, proven development/design paradigms. Design patterns come in three different categories. Creational patterns include the generation of object instances. Structure refers to how an object is made and how things behave and interact In this Webinar(Live Meetup) we will be covering - What is node js - When to use node js - Async I/O operations in node js - Advantages of Async/Await - Some interesting - async patterns - Performance comparison
In this talk we will take a trip into the world of iteration in JavaScript. If we would be talking only about `while`, `do while`, `for`, `Array.map`, `Array.forEach` and so on, this talk would be rather boring, so we will focus on the JavaScript iteration protocols and learn how to build our custom Async Iterators and generators!
An opinionated intro to Node.js - devrupt hospitality hackathonLuciano Mammino
A talk presenting an opinionated introduction to Node.js, proving a simple introduction to the async model, some common async patterns and some other interesting Node.js tricks.
A talk presenting an opinionated introduction to Node.js, proving a simple introduction to the async model, some common async patterns and some other interesting Node.js tricks.
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
HotSpot promises to do the "right" thing for us by identifying our hot code and compiling "just-in-time", but how does HotSpot make those decisions?
This presentation aims to detail how HotSpot makes those decisions and how it corrects its mistakes through a series of demos that you run yourself.
In this talk we will take a trip into the world of iteration in JavaScript. If we would be talking only about `while`, `do while`, `for`, `Array.map`, `Array.forEach` and so on, this talk would be rather boring, so we will focus on the JavaScript iteration protocols and learn how to build our custom Async Iterators and generators!
An opinionated intro to Node.js - devrupt hospitality hackathonLuciano Mammino
A talk presenting an opinionated introduction to Node.js, proving a simple introduction to the async model, some common async patterns and some other interesting Node.js tricks.
A talk presenting an opinionated introduction to Node.js, proving a simple introduction to the async model, some common async patterns and some other interesting Node.js tricks.
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
HotSpot promises to do the "right" thing for us by identifying our hot code and compiling "just-in-time", but how does HotSpot make those decisions?
This presentation aims to detail how HotSpot makes those decisions and how it corrects its mistakes through a series of demos that you run yourself.
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
JavaScript is single threaded, so understanding the async patterns available in the language is critical to creating maintainable NodeJS applications with good performance. In order to master “thinking in async”, we’ll explore the async patterns available in node and JavaScript including standard callbacks, promises, thunks/tasks, the new async/await, the upcoming asynchronous iteration features, streams, CSP and ES Observables.
One of JavaScript’s strengths is how it handles asynchrony. Async is one of the most important and often misunderstood part of Javascript or any other language. We will see how dealing with asynchrony in JavaScript evolved over the years. It all started with callbacks, it landed on generators and...
Azul Virtual Machine Engineer Douglas Hawkins describes how decisions made by the JVM affect how your code is compiled and run. Learn how this affects application performance and what steps you can take to optimize how the JVM acts on your code.
Dive into core asynchronous patterns in modern JavaScript. Comparing the tradeoffs of callbacks, thunks, promises, generators and async/await and demonstrating how each pattern builds on top of the previous. Touching on concepts like the Event Queue, Single-threaded, Run to Completion and Non-Blocking. Showing how we can deal with things happening “at the same time“ and maybe even completely eliminate time as a concern.
Playing With Fire - An Introduction to Node.jsMike Hagedorn
node.js is an evented server-side Javascript framework powered by the Google V8 Javascript engine. It is a platform ideal for creating highly scalable web applications. It has the same simplicity of frameworks such as Sinatra, but is designed to be more peformant from the ground up. This performance is achieved by making all network I/O non blocking and all file I/O asynchronous. We will go over how that impacts the development experience, and walk through a simple web application. Javascript is foundational to this type of I/O because it is already evented by design. We will also take a brief look a similar evented frameworks such as ruby`s EventMachine.
Asynchronous web apps with the Play Framework 2.0Oscar Renalias
Brief introduction to the asynchronous and reactive IO capabilities available in Play 2.0.
Source code of the demos available here: https://github.com/oscarrenalias/wjax-2012-play-async-apps
JavaScript Iteration Protocols - Workshop NodeConf EU 2022Luciano Mammino
How many ways do you know to do iteration with JavaScript and Node.js? While, for loop, for...in, for..of, .map(), .forEach(), streams, iterators, etc! Yes, there are a lot of ways! But did you know that JavaScript has iteration protocols to standardise synchronous and even asynchronous iteration? In this workshop we will learn about these protocols and discover how to build iterators and iterable objects, both synchronous and asynchronous. We will learn about some common use cases for these protocols, explore generators and async generators (great tools for iteration) and finally discuss some hot tips, common pitfalls, and some (more or less successful) wild ideas!
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
Salah satu front-end developer GITS Indonesia, Warsono, mengisi workshop di universitas, mengenai Vue.js.
Ikuti kami di kanal berikut, agar tidak ketinggalan acara seru:
Instagram: @gitsindonesia
LinkedIn: GITS Indonesia
Website: gits.id
asyncio - is young library for asynchronous network programming. Lack of information on proper use and writing code in asyncio as well as production war stories slows down asyncio adoption.
In this talk I'll cover my experience with asyncio in production, best practices for writing reliable and testable asynchronous code as well as bunch of asyncio tips and tricks. We will discuss how run asyncio application in standalone mode, execute blocking code in event loop and moreover how embed asyncio in your synchronous application.
Page freeze, glitchy animation, and slow scrolling. They follow us everywhere, and we'd like them to stop. This talk will get to the bottom of these issues by delving into the Javascript engine and concepts like task, call-stack, and event-loops. I will also introduce several ways to tackle these problems and walk you through a demo to help you understand.
What is event loop. What are the different browser tasks and queues that we have. What is zone.js and how ways to manage the zones in our applications. Persistent execution context between JavaScript async calls. What is monkey patching and how do we intercept zones. Implementing custom change detection.
As a guest speaker in NCU, I gave this second talk about some more advanced practices of JavaScript programming. It summarised our experience learned from developing Mozilla/Gaia project, including the way to deal with asynchronous code flow with the event-driven model.
Did you know JavaScript has iterators? DublinJSLuciano Mammino
How many ways do you know to do iteration with JavaScript and Node.js? While, for loop, for…in, for..of, .map(), .forEach(), streams, iterators, etc! Yes, there are a lot of ways! But did you know that JavaScript has iteration protocols to standardise synchronous and even asynchronous iteration? In this workshop we will learn about these protocols and discover how to build iterators and iterable objects, both synchronous and asynchronous. We will learn about some common use cases for these protocols, explore generators and async generators (great tools for iteration) and finally discuss some hot tips, common pitfalls, and some (more or less successful) wild ideas!
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...Luciano Mammino
In 2020 I started to be a bit more serious about learning Rust. After having read a few books and having done some coding challenges, I decided to start live-streaming my attempts to solve Advent of Code challenges using Rust. Fast forward to 2022 I completed 50 challenges and learned a lot about how to use Rust to solve specific programming challenges. In this talk, I’ll be sharing some common tips and tricks that I discovered while live-coding also thanks to the beautiful Rust community that gave me tons of suggestions! Some topics I’ll be covering in this talk: parsing input, data structures, error handling, iterators, performance, allocating and manipulating 2d matrices, etc.
More Related Content
Similar to From Node.js to Design Patterns - BuildPiper
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
JavaScript is single threaded, so understanding the async patterns available in the language is critical to creating maintainable NodeJS applications with good performance. In order to master “thinking in async”, we’ll explore the async patterns available in node and JavaScript including standard callbacks, promises, thunks/tasks, the new async/await, the upcoming asynchronous iteration features, streams, CSP and ES Observables.
One of JavaScript’s strengths is how it handles asynchrony. Async is one of the most important and often misunderstood part of Javascript or any other language. We will see how dealing with asynchrony in JavaScript evolved over the years. It all started with callbacks, it landed on generators and...
Azul Virtual Machine Engineer Douglas Hawkins describes how decisions made by the JVM affect how your code is compiled and run. Learn how this affects application performance and what steps you can take to optimize how the JVM acts on your code.
Dive into core asynchronous patterns in modern JavaScript. Comparing the tradeoffs of callbacks, thunks, promises, generators and async/await and demonstrating how each pattern builds on top of the previous. Touching on concepts like the Event Queue, Single-threaded, Run to Completion and Non-Blocking. Showing how we can deal with things happening “at the same time“ and maybe even completely eliminate time as a concern.
Playing With Fire - An Introduction to Node.jsMike Hagedorn
node.js is an evented server-side Javascript framework powered by the Google V8 Javascript engine. It is a platform ideal for creating highly scalable web applications. It has the same simplicity of frameworks such as Sinatra, but is designed to be more peformant from the ground up. This performance is achieved by making all network I/O non blocking and all file I/O asynchronous. We will go over how that impacts the development experience, and walk through a simple web application. Javascript is foundational to this type of I/O because it is already evented by design. We will also take a brief look a similar evented frameworks such as ruby`s EventMachine.
Asynchronous web apps with the Play Framework 2.0Oscar Renalias
Brief introduction to the asynchronous and reactive IO capabilities available in Play 2.0.
Source code of the demos available here: https://github.com/oscarrenalias/wjax-2012-play-async-apps
JavaScript Iteration Protocols - Workshop NodeConf EU 2022Luciano Mammino
How many ways do you know to do iteration with JavaScript and Node.js? While, for loop, for...in, for..of, .map(), .forEach(), streams, iterators, etc! Yes, there are a lot of ways! But did you know that JavaScript has iteration protocols to standardise synchronous and even asynchronous iteration? In this workshop we will learn about these protocols and discover how to build iterators and iterable objects, both synchronous and asynchronous. We will learn about some common use cases for these protocols, explore generators and async generators (great tools for iteration) and finally discuss some hot tips, common pitfalls, and some (more or less successful) wild ideas!
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
Salah satu front-end developer GITS Indonesia, Warsono, mengisi workshop di universitas, mengenai Vue.js.
Ikuti kami di kanal berikut, agar tidak ketinggalan acara seru:
Instagram: @gitsindonesia
LinkedIn: GITS Indonesia
Website: gits.id
asyncio - is young library for asynchronous network programming. Lack of information on proper use and writing code in asyncio as well as production war stories slows down asyncio adoption.
In this talk I'll cover my experience with asyncio in production, best practices for writing reliable and testable asynchronous code as well as bunch of asyncio tips and tricks. We will discuss how run asyncio application in standalone mode, execute blocking code in event loop and moreover how embed asyncio in your synchronous application.
Page freeze, glitchy animation, and slow scrolling. They follow us everywhere, and we'd like them to stop. This talk will get to the bottom of these issues by delving into the Javascript engine and concepts like task, call-stack, and event-loops. I will also introduce several ways to tackle these problems and walk you through a demo to help you understand.
What is event loop. What are the different browser tasks and queues that we have. What is zone.js and how ways to manage the zones in our applications. Persistent execution context between JavaScript async calls. What is monkey patching and how do we intercept zones. Implementing custom change detection.
As a guest speaker in NCU, I gave this second talk about some more advanced practices of JavaScript programming. It summarised our experience learned from developing Mozilla/Gaia project, including the way to deal with asynchronous code flow with the event-driven model.
Similar to From Node.js to Design Patterns - BuildPiper (20)
Did you know JavaScript has iterators? DublinJSLuciano Mammino
How many ways do you know to do iteration with JavaScript and Node.js? While, for loop, for…in, for..of, .map(), .forEach(), streams, iterators, etc! Yes, there are a lot of ways! But did you know that JavaScript has iteration protocols to standardise synchronous and even asynchronous iteration? In this workshop we will learn about these protocols and discover how to build iterators and iterable objects, both synchronous and asynchronous. We will learn about some common use cases for these protocols, explore generators and async generators (great tools for iteration) and finally discuss some hot tips, common pitfalls, and some (more or less successful) wild ideas!
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...Luciano Mammino
In 2020 I started to be a bit more serious about learning Rust. After having read a few books and having done some coding challenges, I decided to start live-streaming my attempts to solve Advent of Code challenges using Rust. Fast forward to 2022 I completed 50 challenges and learned a lot about how to use Rust to solve specific programming challenges. In this talk, I’ll be sharing some common tips and tricks that I discovered while live-coding also thanks to the beautiful Rust community that gave me tons of suggestions! Some topics I’ll be covering in this talk: parsing input, data structures, error handling, iterators, performance, allocating and manipulating 2d matrices, etc.
Building an invite-only microsite with Next.js & Airtable - ReactJS MilanoLuciano Mammino
Imagine you are hosting a private event and you want to create a website to invite all your guests. Of course, you’d like to have an easy way to just share a URL with every guest and they should be able to access all the details of the event. Everyone else should not be allowed to see the page. Even nicer if the website is customized for every guest and if you could use the same website to collect information from the guests (who is coming and who is not). Ok, how do we build all of this? But, most importantly, how do we build it quickly? How do we keep it simple and possibly host it 100% for FREE? I had to do something like this recently so, in this talk, I am going to share my solution, which involves a React SPA (built with Next.js & Vercel) and AirTable as a backend! In the process, we are going to learn some tricks, like how to build a custom React Hook and how to protect our app from AirTable query injection (yes, it’s a thing)!
Let's build a 0-cost invite-only website with Next.js and Airtable!Luciano Mammino
Imagine you are hosting a private event and you want to create a website to invite all your guests. Of course, you’d like to have an easy way to just share a URL with every guest and they should be able to access all the details of the event. Everyone else should not be allowed to see the page. Even nicer if the website is customized for every guest and if you could use the same website to collect information from the guests (who is coming and who is not). Ok, how do we build all of this? But, most importantly, how do we build it quickly? How do we keep it simple and possibly host it 100% for FREE? I had to do something like this recently so, in this talk, I am going to share my solution, which involves a React SPA (built with Next.js & Vercel) and AirTable as a backend! In the process, we are going to learn some tricks, like how to build a custom React Hook and how to protect our app from AirTable query injection (yes, it’s a thing)!
Almost every web application at some point needs a way to upload or download files… and no one seems to enjoy building reliable and scalable upload/download servers… and for good reasons too! In fact, you’ll probably need to manage long-running connections and handle files that can be quite large (i.e videos). If you are running a fully serverless backend using API Gateway and Lambda, you probably know that you are limited in terms of payload size and execution time, so things get even more complicated there. In all these cases you should consider offloading this problem to S3 by using S3 pre-signed URLs. Pre-signed URLs are a fantastic tool to handle file download and upload directly in S3 in a managed and scalable fashion. But all that glitters is not gold and S3 pre-signed URLs come with quite a few gotchas… So in this talk, we will explore some use cases, see some potential implementations of S3 pre-signed URLs and uncover some of the gotchas that I discovered while using them. By the end of this talk, you should know exactly when to use pre-signed URLs and how to avoid most of the many mistakes I made with them!
Serverless is great for web applications and APIs, but this does not mean it cannot be used successfully for other use cases. In this talk, we will discuss a successful application of serverless in the field of High Performance Computing. Specifically we will discuss how Lambda, Fargate, Kinesis and other serverless technologies are being used to run sophisticated financial models at one of the major reinsurance companies in the World. We we learn about the architecture, the tradeoffs, some challenges and some unresolved pain points. Most importantly, we'll find out if serverless can be a great fit for HPC and if we can finally stop managing those boring EC2 instances!
Serverless is great for web applications and APIs, but this does not mean it cannot be used successfully for other use cases. In this talk, we will discuss a successful application of serverless in the field of High Performance Computing. Specifically we will discuss how Lambda, Fargate, Kinesis and other serverless technologies are being used to run sophisticated financial models at one of the major reinsurance companies in the World. We we learn about the architecture, the tradeoffs, some challenges and some unresolved pain points. Most importantly, we'll find out if serverless can be a great fit for HPC and if we can finally stop managing those boring EC2 instances!
Building an invite-only microsite with Next.js & AirtableLuciano Mammino
Imagine you are hosting a private event and you want to create a website to invite all your guests. Of course you'd like to have an easy way to just share a URL with every guest and they should be able to access all the details of the event. Everyone else should not be allowed to see the page. Even nicer if the website is customized for every guest and if you could use the same website to collect information from the guests (who is coming and who is not). Ok, how do we build all of this? But, most importantly, how do we build it quickly? How do we keep it simple and possibly host it 100% for FREE? I had to do something like this recently so, in this talk, I am going to share my solution, which involves a React SPA (built with Next.js & Vercel) and AirTable as a backend!
How can you take an existing monolith to the cloud with very minimal effort? In this talk we will explore an architecture that can help you to achieve that while focusing on scalability and resilience.
A look inside the European Covid Green Certificate - Rust DublinLuciano Mammino
When I saw how dense the European Covid Green Pass QR code is, I got immediately curious: "WOW, there must be a lot of interesting data in here". So, I started to dig deeper and I found that there's really a great wealth of interesting encoding and verification technologies being used in it! In this talk, I will share what I learned! We will go on a journey where we will explore Base54 encoding, COSE tokens, CBOR serialization, elliptic curve crypto, and much more! Finally, I will also show you how to write a decoder for Green Pass certificates in the most hyped language ever: Rust!
How can you take an existing monolith to the cloud with very minimal effort? In this talk we will explore an architecture that can help you to achieve that while focusing on scalability and resilience.
A presentation by Luciano Mammino(@loige) about what it takes to be recognised as a Senior Software Engineer:
The goal of this slides deck is to:
- Discuss what is expected from a senior software engineer (skills, mindset, duties)
- Packed with opinions (my own and more)
- For devs to be inspired
- For managers to hire, set expectations, support, and evaluate
Node.js: scalability tips - Azure Dev Community VijayawadaLuciano Mammino
You finally built that amazing start-up idea you had in mind for years and you did it using Node.js! That's Great! You just launched it on Hacker News and you are very happy and proud... but now more and more people are using it and you start to have a nasty fear that Node.js won't scale because you now... it's single-threaded! Is your project doomed now? Do you have to invest your time on rewriting it in something like C++ or maybe Rust or even Go? You'd rather invest your time on adding valuable features for your users rather than learning a new language and rewriting everything from scratch, but what if nothing works anymore? And... by the way, what the heck "single-threaded" really means?! Fear no more, dear fellow developer! In this talk, we will discuss the architecture of Node.js going through its strengths and its weaknesses. We will then talk about scalability and I will share some valuable tips and tricks to make your Node.js app scale! Spoiler alert: you probably won't need Go or Rust :)
A look inside the European Covid Green Certificate (Codemotion 2021)Luciano Mammino
When I saw how dense the European Covid Green Pass QR code is, I got immediately curious: "WOW, there must be a lot of interesting data in here". So, I started to dig deeper and I found that there's really a great wealth of interesting encoding and verification technologies being used in it! In this talk, I will share what I learned! We will go on a journey where we will explore Base54 encoding, COSE tokens, CBOR serialization, elliptic curve crypto, and much more! Finally, I will also show you how to write a decoder for Green Pass certificates in the most hyped language ever: Rust!
Have you ever thought that your Lambda functions could fail without you even noticing?
If the answer is YES, that’s probably because you already “burnt" yourself playing with the cloud, where errors and failures are always around the corner…
Unfortunately we can’t prevent all types of failures, but what we can do is try to spot them as soon as possible and react quickly.
In order to do that, we need good observability for our serverless applications and therefore we need to become good friends with services like CloudWatch.
If you have tried CloudWatch already, you probably know how powerful but also complex it can be…
In this talk we will approach the topic of observability for serverless applications on AWS. We will discuss best practices and how to build a good friendship with CloudWatch.
We will also present some interesting automation tools that we can use to take away most of the pain of setting up dashboards and alarms in CloudWatch, making it easier to achieve great levels of observability.
Semplificare l'observability per progetti ServerlessLuciano Mammino
Hai mai pensato che le tue lambda functions possano fallire senza che tu te ne accorga? Se la risposta é "SI" probabilmente é perché ti sei giá "bruciato" giocando con il cloud, dove errori e fallimenti sono sempre dietro l'angolo. Purtroppo non possiamo prevenire tutti i fallimenti, pero' possiamo essere notificati quando qualcosa va storto cosí da poter reagire tempestivamente. Ma come fare a configurare il nostro ambiente AWS per raggiungere un buon livello di "Observability"? Se hai giá provato ad utilizzare CloudWatch saprai giá quanto possa essere complesso. In questo talk, esploreremo il tema dell'observability per applicazioni Serverless su AWS. Discuteremo problemi e best practices. Infine vi proporró un tool che permette di automatizzare la configurazione di CloudWatch per l'80% delle esigenze in pochi minuti!
Finding a lost song with Node.js and async iterators - NodeConf Remote 2021Luciano Mammino
Did you ever get that feeling when a random song pops into your brain and you can’t get rid of it? Well, that happened to me recently and I couldn’t even remember the title of the damn song! In this talk, I want to share with you the story of how I was able to recover the details of the song by navigating some music-related APIs using JavaScript, Node.js and the magic of async iterators!
Finding a lost song with Node.js and async iterators - EnterJS 2021Luciano Mammino
Did you ever get that feeling when a random song pops into your brain and you can’t get rid of it? Well, that happened to me recently and I couldn’t even remember the title of the damn song! In this talk, I want to share with you the story of how I was able to recover the details of the song by navigating some music-related APIs using JavaScript, Node.js and the magic of async iterators!
Most AWS APIs will have limits on the amount of data you can send in one request and sometimes you really need to send a lot of data! To try to maximise the amount of data you can send, while still staying within the limits, some APIs support sending gzip-compressed payloads. But how can you send a gzipped request when using the Python SDK for AWS (boto3)? Well, I needed to answer this question recently and it turned out not to be as easy as I anticipated… Let’s jump into this rabbit hole together and let’s find out the answer!
Finding a lost song with Node.js and async iteratorsLuciano Mammino
Did you ever get that feeling when a random song pops into your brain and you can’t get rid of it? Well, that happened to me recently and I couldn’t even remember the title of the damn song! In this talk, I want to share with you the story of how I was able to recover the details of the song by navigating some music-related APIs using JavaScript, Node.js and the magic of async iterators!
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
3. Always re-imagining
We are a pioneering technology consultancy focused
on AWS and serverless
| |
Accelerated Serverless AI as a Service Platform Modernisation
loige
✉Reach out to us at
😇We are always looking for talent:
hello@fourTheorem.com
fth.link/careers
3
4. We host a weekly podcast about AWS
awsbites.com
loige 4
7. What does async even mean?
In JavaScript and in Node.js, input/output operations are non-
blocking.
Classic examples: reading the content of a file, making an HTTP
request, loading data from a database, etc.
loige 7
8. Blocking style vs JavaScript
Blocking style JavaScript
1. Assign a variable
2. Read data from a file
3. Print to stdout
1. Assign a variable
2. Read data from a file
3. Print to stdout
loige 8
9. Blocking style vs JavaScript
Blocking style JavaScript
1. Assign a variable
2. Read data from a file
3. Print to stdout
1. Assign a variable
2. Read data from a file
3. Print to stdout
loige 9
10. Blocking style vs JavaScript
Blocking style JavaScript
1. Assign a variable
2. Read data from a file
3. Print to stdout
1. Assign a variable
2. Read data from a file
3. Print to stdout
loige 10
11. Blocking style vs JavaScript
Blocking style JavaScript
1. Assign a variable
2. Read data from a file
3. Print to stdout
1. Assign a variable
2. Read data from a file
3. Print to stdout
loige 11
12. Blocking style vs JavaScript
Blocking style JavaScript
1. Assign a variable
2. Read data from a file
3. Print to stdout
1. Assign a variable
2. Read data from a file
3. Print to stdout
(done)
loige 12
13. Blocking style vs JavaScript
Blocking style JavaScript
1. Assign a variable
2. Read data from a file
3. Print to stdout
1. Assign a variable
2. Read data from a file
3. Print to stdout
(done)
(done)
loige 13
14. Non-blocking I/O is convenient:
you can do work while waiting for I/O!
But, what if we need to do something when
the I/O operation completes?
loige 14
15. Once upon a time there were...
Callbacks
loige 15
16. Anatomy of callback-based non-blocking code
doSomethingAsync(arg1, arg2, cb)
This is a callback
loige 16
17. doSomethingAsync(arg1, arg2, (err, data) => {
// ... do something with data
})
You are defining what happens when the I/O operations
completes (or fails) with a function.
doSomethingAsync will call that function for you!
loige
Anatomy of callback-based non-blocking code
17
18. doSomethingAsync(arg1, arg2, (err, data) => {
if (err) {
// ... handle error
return
}
// ... do something with data
})
Always handle errors first!
loige
Anatomy of callback-based non-blocking code
18
19. An example
Fetch the latest booking for a given user
If it exists print it
loige 19
20. getLatestBooking(userId, (err, booking) => {
if (err) {
console.error(err)
return
}
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
} else {
console.log(`No booking found for user ${userId}`)
}
})
1
2
3
4
5
6
7
8
9
10
11
12
An example
loige 20
21. A more realistic example
Fetch the latest booking for a given user
If it exists, cancel it
If it was already paid for, refund the user
loige 21
22. getLatestBooking(userId, (err, booking) => {
if (err) {
console.error(err)
return
}
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
cancelBooking(booking.id, (err) => {
if (err) {
console.error(err)
return
}
if (booking.paid) {
console.log('Booking was paid, refunding the user')
refundUser(userId, booking.paidAmount, (err) => {
if (err) {
console.error(err)
return
}
console.log('User refunded')
})
}
})
} else {
console.log(`No booking found for user ${userId}`)
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cancelBooking(booking.id, (err) => {
if (err) {
console.error(err)
return
}
if (booking.paid) {
console.log('Booking was paid, refunding the user')
refundUser(userId, booking.paidAmount, (err) => {
if (err) {
console.error(err)
return
}
console.log('User refunded')
})
}
})
getLatestBooking(userId, (err, booking) => {
1
if (err) {
2
console.error(err)
3
return
4
}
5
6
if (booking) {
7
console.log(`Found booking for user ${userId}`, booking)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
} else {
27
console.log(`No booking found for user ${userId}`)
28
}
29
})
30
if (booking.paid) {
console.log('Booking was paid, refunding the user')
refundUser(userId, booking.paidAmount, (err) => {
if (err) {
console.error(err)
return
}
console.log('User refunded')
})
}
getLatestBooking(userId, (err, booking) => {
1
if (err) {
2
console.error(err)
3
return
4
}
5
6
if (booking) {
7
console.log(`Found booking for user ${userId}`, booking)
8
cancelBooking(booking.id, (err) => {
9
if (err) {
10
console.error(err)
11
return
12
}
13
14
15
16
17
18
19
20
21
22
23
24
25
})
26
} else {
27
console.log(`No booking found for user ${userId}`)
28
}
29
})
30
refundUser(userId, booking.paidAmount, (err) => {
if (err) {
console.error(err)
return
}
console.log('User refunded')
})
getLatestBooking(userId, (err, booking) => {
1
if (err) {
2
console.error(err)
3
return
4
}
5
6
if (booking) {
7
console.log(`Found booking for user ${userId}`, booking)
8
cancelBooking(booking.id, (err) => {
9
if (err) {
10
console.error(err)
11
return
12
}
13
14
if (booking.paid) {
15
console.log('Booking was paid, refunding the user')
16
17
18
19
20
21
22
23
24
}
25
})
26
} else {
27
console.log(`No booking found for user ${userId}`)
28
}
29
})
30 loige 22
23. getLatestBooking(userId, (err, booking) => {
if (err) {
console.error(err)
return
}
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
cancelBooking(booking.id, (err) => {
if (err) {
console.error(err)
return
}
if (booking.paid) {
console.log('Booking was paid, refunding the user')
refundUser(userId, booking.paidAmount, (err) => {
if (err) {
console.error(err)
return
}
console.log('User refunded')
})
}
})
} else {
console.log(`No booking found for user ${userId}`)
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 loige 23
24. getLatestBooking(userId, (err, booking) => {
if (err) {
console.error(err)
return
}
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
cancelBooking(booking.id, (err) => {
if (err) {
console.error(err)
return
}
if (booking.paid) {
console.log('Booking was paid, refunding the user')
refundUser(userId, booking.paidAmount, (err) => {
if (err) {
console.error(err)
return
}
console.log('User refunded')
})
}
})
} else {
console.log(`No booking found for user ${userId}`)
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 loige
THE PIRAMID OF
DOOM
(or callback hell 🔥)
24
30. With callbacks we are not in
charge!
We need to trust that the async function will call our
callbacks when the async work is completed!
loige 30
31. Promise help us to be more in control!
const promiseObj = doSomethingAsync(arg1, arg2)
An object that represents the
status of the async operation
loige 31
32. const promiseObj = doSomethingAsync(arg1, arg2)
A promise object is a tiny state machine with 2 possible states
pending (still performing the async operation)
settled (completed)
✅fullfilled (witha value)
🔥rejected (with an error)
loige
Promise help us to be more in control!
32
33. const promiseObj = doSomethingAsync(arg1, arg2)
promiseObj.then((data) => {
// ... do something with data
})
loige
Promise help us to be more in control!
33
34. const promiseObj = doSomethingAsync(arg1, arg2)
promiseObj.then((data) => {
// ... do something with data
})
promiseObj.catch((err) => {
// ... handle errors
}
loige
Promise help us to be more in control!
34
35. Promises can be chained ⛓
This solves the pyramid of doom problem!
doSomethingAsync(arg1, arg2)
.then((result) => doSomethingElseAsync(result))
.then((result) => doEvenMoreAsync(result)
.then((result) => keepDoingStuffAsync(result))
.catch((err) => { /* ... */ })
35
loige
36. Promises can be chained ⛓
This solves the pyramid of doom problem!
doSomethingAsync(arg1, arg2)
.then((result) => doSomethingElseAsync(result))
// ...
.catch((err) => { /* ... */ })
.finally(() => { /* ... */ })
loige 36
37. How to create a promise
new Promise ((resolve, reject) => {
// ...
})
loige 37
38. How to create a promise
new Promise ((resolve, reject) => {
// ... do something async
// reject(someError)
// resolve(someValue)
})
loige 38
39. How to create a promise
Promise.resolve('SomeValue')
Promise.reject(new Error('SomeError'))
loige 39
40. How to create a promise (example)
function queryDB(client, query) {
return new Promise((resolve, reject) => {
client.executeQuery(query, (err, data) => {
if (err) {
return reject(err)
}
resolve(data)
})
})
}
1
2
3
4
5
6
7
8
9
10
11
loige 40
41. How to create a promise (example)
queryDB(dbClient, 'SELECT * FROM bookings')
.then((data) => {
// ... do something with data
})
.catch((err) => {
console.error('Failed to run query', err)
})
.finally(() => {
dbClient.disconnect()
})
1
2
3
4
5
6
7
8
9
10
queryDB(dbClient, 'SELECT * FROM bookings')
1
.then((data) => {
2
// ... do something with data
3
})
4
.catch((err) => {
5
console.error('Failed to run query', err)
6
})
7
.finally(() => {
8
dbClient.disconnect()
9
})
10
.then((data) => {
// ... do something with data
})
queryDB(dbClient, 'SELECT * FROM bookings')
1
2
3
4
.catch((err) => {
5
console.error('Failed to run query', err)
6
})
7
.finally(() => {
8
dbClient.disconnect()
9
})
10
.catch((err) => {
console.error('Failed to run query', err)
})
queryDB(dbClient, 'SELECT * FROM bookings')
1
.then((data) => {
2
// ... do something with data
3
})
4
5
6
7
.finally(() => {
8
dbClient.disconnect()
9
})
10
.finally(() => {
dbClient.disconnect()
})
queryDB(dbClient, 'SELECT * FROM bookings')
1
.then((data) => {
2
// ... do something with data
3
})
4
.catch((err) => {
5
console.error('Failed to run query', err)
6
})
7
8
9
10
queryDB(dbClient, 'SELECT * FROM bookings')
.then((data) => {
// ... do something with data
})
.catch((err) => {
console.error('Failed to run query', err)
})
.finally(() => {
dbClient.disconnect()
})
1
2
3
4
5
6
7
8
9
10
loige 41
42. Let's re-write our example with Promise
Fetch the latest booking for a given user
If it exists, cancel it
If it was already paid for, refund the user
loige 42
43. getLatestBooking(userId)
.then((booking) => {
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
return cancelBooking(booking.id)
}
console.log(`No booking found for user ${userId}`)
})
.then((cancelledBooking) => {
if (cancelledBooking && cancelledBooking.paid) {
console.log('Booking was paid, refunding the user')
return refundUser(userId, cancelledBooking.paidAmount)
}
})
.then((refund) => {
if (refund) {
console.log('User refunded')
}
})
.catch((err) => {
console.error(err)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
getLatestBooking(userId)
1
.then((booking) => {
2
if (booking) {
3
console.log(`Found booking for user ${userId}`, booking)
4
return cancelBooking(booking.id)
5
}
6
console.log(`No booking found for user ${userId}`)
7
})
8
.then((cancelledBooking) => {
9
if (cancelledBooking && cancelledBooking.paid) {
10
console.log('Booking was paid, refunding the user')
11
return refundUser(userId, cancelledBooking.paidAmount)
12
}
13
})
14
.then((refund) => {
15
if (refund) {
16
console.log('User refunded')
17
}
18
})
19
.catch((err) => {
20
console.error(err)
21
})
22
.then((booking) => {
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
return cancelBooking(booking.id)
}
console.log(`No booking found for user ${userId}`)
})
getLatestBooking(userId)
1
2
3
4
5
6
7
8
.then((cancelledBooking) => {
9
if (cancelledBooking && cancelledBooking.paid) {
10
console.log('Booking was paid, refunding the user')
11
return refundUser(userId, cancelledBooking.paidAmount)
12
}
13
})
14
.then((refund) => {
15
if (refund) {
16
console.log('User refunded')
17
}
18
})
19
.catch((err) => {
20
console.error(err)
21
})
22
.then((cancelledBooking) => {
if (cancelledBooking && cancelledBooking.paid) {
console.log('Booking was paid, refunding the user')
return refundUser(userId, cancelledBooking.paidAmount)
}
})
getLatestBooking(userId)
1
.then((booking) => {
2
if (booking) {
3
console.log(`Found booking for user ${userId}`, booking)
4
return cancelBooking(booking.id)
5
}
6
console.log(`No booking found for user ${userId}`)
7
})
8
9
10
11
12
13
14
.then((refund) => {
15
if (refund) {
16
console.log('User refunded')
17
}
18
})
19
.catch((err) => {
20
console.error(err)
21
})
22
.then((refund) => {
if (refund) {
console.log('User refunded')
}
})
getLatestBooking(userId)
1
.then((booking) => {
2
if (booking) {
3
console.log(`Found booking for user ${userId}`, booking)
4
return cancelBooking(booking.id)
5
}
6
console.log(`No booking found for user ${userId}`)
7
})
8
.then((cancelledBooking) => {
9
if (cancelledBooking && cancelledBooking.paid) {
10
console.log('Booking was paid, refunding the user')
11
return refundUser(userId, cancelledBooking.paidAmount)
12
}
13
})
14
15
16
17
18
19
.catch((err) => {
20
console.error(err)
21
})
22
.catch((err) => {
console.error(err)
})
getLatestBooking(userId)
1
.then((booking) => {
2
if (booking) {
3
console.log(`Found booking for user ${userId}`, booking)
4
return cancelBooking(booking.id)
5
}
6
console.log(`No booking found for user ${userId}`)
7
})
8
.then((cancelledBooking) => {
9
if (cancelledBooking && cancelledBooking.paid) {
10
console.log('Booking was paid, refunding the user')
11
return refundUser(userId, cancelledBooking.paidAmount)
12
}
13
})
14
.then((refund) => {
15
if (refund) {
16
console.log('User refunded')
17
}
18
})
19
20
21
22
getLatestBooking(userId)
.then((booking) => {
if (booking) {
console.log(`Found booking for user ${userId}`, booking)
return cancelBooking(booking.id)
}
console.log(`No booking found for user ${userId}`)
})
.then((cancelledBooking) => {
if (cancelledBooking && cancelledBooking.paid) {
console.log('Booking was paid, refunding the user')
return refundUser(userId, cancelledBooking.paidAmount)
}
})
.then((refund) => {
if (refund) {
console.log('User refunded')
}
})
.catch((err) => {
console.error(err)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
loige 43
45. Sometimes, we just want to wait for a promise to
resolve before executing the next line...
const promiseObj = doSomethingAsync(arg1, arg2)
const data = await promiseObj
// ... process the data
await allows us to do exactly that
loige 45
46. const data = await doSomethingAsync(arg1, arg2)
// ... process the data
We don't have to assign the promise to a variable to use await
Sometimes, we just want to wait for a promise to
resolve before executing the next line...
loige 46
47. try {
const data = await doSomethingAsync(arg1, arg2)
// ... process the data
} catch (err) {
// ... handle error
}
Unified error handling
If we await a promise that eventually rejects we can capture the error with a regular try/catch block
loige 47
48. Async functions
async function doSomethingAsync(arg1, arg2) {
// ...
}
special keyword that marks a function as async
loige 48
49. Async functions
async function doSomethingAsync(arg1, arg2) {
return 'SomeValue'
}
function doSomethingAsync(arg1, arg2) {
return Promise.resolve('SomeValue')
}
loige 49
50. Async functions
async function doSomethingAsync(arg1, arg2) {
throw new Error('SomeError')
}
function doSomethingAsync(arg1, arg2) {
return Promise.reject(new Error('SomeError'))
}
loige 50
51. Async functions
async function doSomethingAsync(arg1, arg2) {
const res1 = await doSomethingElseAsync()
const res2 = await doEvenMoreAsync(res1)
const res3 = await keepDoingStuffAsync(res2)
// ...
}
inside an async function you can use await to
suspend the execution until the awaited promise
resolves
loige 51
52. Async functions
async function doSomethingAsync(arg1, arg2) {
const res = await doSomethingElseAsync()
if (res) {
for (const record of res1.records) {
await updateRecord(record)
}
}
}
Async functions make it very easy to write code
that manages asynchronous control flow
loige 52
53. Let's re-write our example with async/await
Fetch the latest booking for a given user
If it exists, cancel it
If it was already paid for, refund the user
loige 53
54. async function cancelLatestBooking(userId) {
const booking = await getLatestBooking(userId)
if (!booking) {
console.log(`No booking found for user ${userId}`)
return
}
console.log(`Found booking for user ${userId}`, booking)
await cancelBooking(booking.id)
if (booking.paid) {
console.log('Booking was paid, refunding the user')
await refundUser(userId, booking.paidAmount)
console.log('User refunded')
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
async function cancelLatestBooking(userId) {
}
1
const booking = await getLatestBooking(userId)
2
3
if (!booking) {
4
console.log(`No booking found for user ${userId}`)
5
return
6
}
7
8
console.log(`Found booking for user ${userId}`, booking)
9
10
await cancelBooking(booking.id)
11
12
if (booking.paid) {
13
console.log('Booking was paid, refunding the user')
14
await refundUser(userId, booking.paidAmount)
15
console.log('User refunded')
16
}
17
18
const booking = await getLatestBooking(userId)
async function cancelLatestBooking(userId) {
1
2
3
if (!booking) {
4
console.log(`No booking found for user ${userId}`)
5
return
6
}
7
8
console.log(`Found booking for user ${userId}`, booking)
9
10
await cancelBooking(booking.id)
11
12
if (booking.paid) {
13
console.log('Booking was paid, refunding the user')
14
await refundUser(userId, booking.paidAmount)
15
console.log('User refunded')
16
}
17
}
18
if (!booking) {
console.log(`No booking found for user ${userId}`)
return
}
async function cancelLatestBooking(userId) {
1
const booking = await getLatestBooking(userId)
2
3
4
5
6
7
8
console.log(`Found booking for user ${userId}`, booking)
9
10
await cancelBooking(booking.id)
11
12
if (booking.paid) {
13
console.log('Booking was paid, refunding the user')
14
await refundUser(userId, booking.paidAmount)
15
console.log('User refunded')
16
}
17
}
18
console.log(`Found booking for user ${userId}`, booking)
async function cancelLatestBooking(userId) {
1
const booking = await getLatestBooking(userId)
2
3
if (!booking) {
4
console.log(`No booking found for user ${userId}`)
5
return
6
}
7
8
9
10
await cancelBooking(booking.id)
11
12
if (booking.paid) {
13
console.log('Booking was paid, refunding the user')
14
await refundUser(userId, booking.paidAmount)
15
console.log('User refunded')
16
}
17
}
18
await cancelBooking(booking.id)
async function cancelLatestBooking(userId) {
1
const booking = await getLatestBooking(userId)
2
3
if (!booking) {
4
console.log(`No booking found for user ${userId}`)
5
return
6
}
7
8
console.log(`Found booking for user ${userId}`, booking)
9
10
11
12
if (booking.paid) {
13
console.log('Booking was paid, refunding the user')
14
await refundUser(userId, booking.paidAmount)
15
console.log('User refunded')
16
}
17
}
18
if (booking.paid) {
console.log('Booking was paid, refunding the user')
await refundUser(userId, booking.paidAmount)
console.log('User refunded')
}
async function cancelLatestBooking(userId) {
1
const booking = await getLatestBooking(userId)
2
3
if (!booking) {
4
console.log(`No booking found for user ${userId}`)
5
return
6
}
7
8
console.log(`Found booking for user ${userId}`, booking)
9
10
await cancelBooking(booking.id)
11
12
13
14
15
16
17
}
18
async function cancelLatestBooking(userId) {
const booking = await getLatestBooking(userId)
if (!booking) {
console.log(`No booking found for user ${userId}`)
return
}
console.log(`Found booking for user ${userId}`, booking)
await cancelBooking(booking.id)
if (booking.paid) {
console.log('Booking was paid, refunding the user')
await refundUser(userId, booking.paidAmount)
console.log('User refunded')
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
loige 54
55. Mini summary
Async/Await generally helps to keep the code simple &
readable
To use Async/Await you need to understand Promise
To use Promise you need to understand callbacks
callbacks → Promise → async/await
Don't skip any step of the async journey!
loige 55
58. Sequential execution (gotcha!)
const users = ['Peach', 'Toad', 'Mario', 'Luigi']
users.forEach(async (userId) => {
await cancelLatestBooking(userId)
})
1
2
3
4
5
loige
⚠Don't do this with Array.map() or Array.forEach()
Array.forEach() will run the provided function without
awaiting for the returned promise, so all the invocation will
actually happen concurrently!
58
59. Concurrent execution (Promise.all)
const users = ['Peach', 'Toad', 'Mario', 'Luigi']
await Promise.all(
users.map(
userId => cancelLatestBooking(userId)
)
)
1
2
3
4
5
6
7
loige
Promise.all() receives a list of promises and it returns a
new Promise. This promise will resolve once all the original
promises resolve, but it will reject as soon as ONE promise
rejects
59
62. You want to use async/await but...
you have a callback-based API! 😣
loige 62
63. Node.js offers promise-based alternative APIs
Callback-based Promise-based
setTimeout, setImmediate, setInterval import timers from 'timers/promises'
import fs from 'fs' import fs from 'fs/promises'
import stream from 'stream' import stream from 'stream/promises'
import dns from 'dns' import dns from 'dns/promises'
loige 63
66. What if we we want to do the opposite? 🤷
Convert a promise-based function to a callback-based one
loige 66
67. var env = nunjucks.configure('views')
env.addFilter('videoTitle', function(videoId, cb) {
// ... fetch the title through youtube APIs
// ... extract the video title
// ... and call the callback with the title
}, true)
1
2
3
4
5
6
7
OK, this is not a common use case, so let me give you a real
example!
Nunjucks async filters
{{ data | myCustomFilter }}
We are forced to pass a callback-based
function here!
Ex: {{ youtubeId | videoTitle }}
loige 67
76. The data fetching function (with batching)
let pendingRequests = new Map()
function getHotelsForCity (cityId) {
if (pendingRequests.has(cityId)) {
return pendingRequests.get(cityId)
}
const asyncOperation = db.query({
text: 'SELECT * FROM hotels WHERE cityid = $1',
values: [cityId],
})
pendingRequests.set(cityId, asyncOperation)
asyncOperation.finally(() => {
pendingRequests.delete(cityId)
})
return asyncOperation
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 loige 76
77. Benchmarks
loige.link/req-batch-bench
Without request batching With request batching (+90% avg req/sec)*
* This is an artificial benchmark and results might vary significantly in real-life scenarios. Always run your own
benchmarks before deciding whether this optimization can have a positive effect for you.
loige 77
78. Closing Notes
JavaScript can be a very powerful and convenient language
when we have to deal with a lot of I/O (e.g. web servers)
The async story has evolved a lot in the last 10-15 years: new
patterns and language constructs have emerged
Async/Await is probably the best way to write async code today
To use Async/Await correctly you need to understand Promise
and callbacks
Take your time and invest in learning the fundamentals
loige 78
79. Cover Picture by on
Marc-Olivier Jodoin Unsplash
THANKS! 🙌❤
nodejsdp.link
loige
Grab these slides!
😍Grab the book
79