SlideShare a Scribd company logo
Async/Await Revisited
We will talk about callback,
promise and async/await.
Hi, I’m Riza
JavaScript is
asyncrhonous
JS waits for nobody

Recommended for you

You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it

How do you measure the quality of your code? Performance and testing are just one aspect of code, in order to meet deadlines and make maintenance quicker you also need your code to be readable, decoupled and generally easier to comprehend and work with. This talk will go over tips and exercises to help you identify trouble areas, refactor them and train you to write better code in future projects. Come make your code look and function better.

readabilityphpcode
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol

The document discusses the history and evolution of jQuery, including major releases and changes over time. It describes how jQuery moved from a concatenated file structure to using RequireJS and module dependencies. It also covers changes in licensing between versions. Finally, it provides examples of how jQuery handles different selector types and error checks selector input.

jquerysizzlejavascrip
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins

As presented at ZendCon 2014, AmsterdamPHP, PHPBenelux 2014, Sweetlake PHP and PHP Northwest 2013, an overview of some different patterns for integrating and managing logic throughout your application.

phpnw13phpphpbnl14
JS will move on without
waiting some process to finish.
Async Example
• Ajax call
• Access user's webcam
• Resize image
How we deal with it?
Good Old Callback

Recommended for you

PHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an AnalysisPHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an Analysis

This document summarizes a presentation about remote code execution in WordPress. It discusses how PHP object injection can allow arbitrary code execution by abusing PHP's unserialize function. It explains how a vulnerability in WordPress' user meta data serialization could allow storing a serialized PHP object in the database that executes code upon unserialization. The presentation provides details on UTF-8 encoding issues in MySQL that can be leveraged as part of an exploit. It then demonstrates a proof-of-concept exploit that uses custom PHP classes to write a file upon page load via callback functions.

Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...

This document discusses exploiting PHP unserialization vulnerabilities. It begins by introducing the presenter and explaining what unserialization is and how it can be insecure if magic methods like __wakeup or __destruct are executed after unserialization. Potential vulnerabilities are demonstrated through examples. The document then discusses more complex chains that can be used to exploit unserialization, including examples from real-world projects like Kohana and exploiting serialized data stored in databases. It describes building a tool to automatically find chains in PHP code that could be exploited via unserialization and demonstrates its use on sample code. The document concludes by noting the challenges of automatically generating exploits due to the lack of static analysis in the tool.

security meetup
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it

Performance and testing are just one aspect of code, to really be successful your code needs to be readable, maintainable and generally easier to comprehend and work with. This talk draws from my own experience in applying the techniques of object calisthenics and code readability, within an existing team. It will help you identify trouble areas, learn how to refactor them and train you to write better code in future projects avoiding common pitfalls.

kings of codephpobject calisthenics
“Callbacks are func!ons that
you pass as arguments to be
invoked when the callee has
finished its job.”
Callback is...
Eric Elliot
getProfile("rizafahmi", (err, profile) 
=> {
getRepos(profile.login, (err, repos) 
=> {
countTotalStars(repos, (err, stars) 
=> {

// count the stars
});
});
});
getProfile("rizafahmi", (err, profile) 
=> {
getRepos(profile.login, (err, repos) 
=> {
countTotalStars(repos, (err, stars) 
=> {

// count the stars
});
});
});
getProfile("rizafahmi", (err, profile) 
=> {
getRepos(profile.login, (err, repos) 
=> {
countTotalStars(repos, (err, stars) 
=> {

// count the stars
});
});
});

Recommended for you

Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators

This document discusses JavaScript generators and how they can be used to simplify asynchronous code. It begins with a simple generator example and then explores more complex use cases like yielding promises, error handling, and parallel processing. Generators allow long-running operations to be written in a synchronous-looking way and are useful for tasks like I/O. When combined with co-routines, they provide a clean way to write asynchronous code that looks synchronous.

es6javascriptgenerators
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf

As developers we write code everyday, only to frown at it a week after that. Why do we have such a hard time with code written by others and ourselves, this raging desire to rewrite everything we see? Writing code that survives the test of time and self judgment is a matter of clarity and simplicity. Let's talk about growing, learning and improving our code with calisthenics, readability and good design.

phpobject calisthenics
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰

This document discusses best practices for developing a chess game app called ChessMate. It covers topics like architecture patterns, design principles, testing practices, code quality, and project organization. Examples are provided to illustrate concepts like separation of concerns, dependency injection, protocol-oriented programming and value types vs reference types. The goal is to build a well-designed, extensible and maintainable chess app following industry standards.

swiftlet swiftosxdev
const handleCountStars = (err, stars) 
=> {
console.log(`Total stars: ${stars}`);
};
const handleRepos = (err, repos) 
=> {
countTotalStars(repos, handleCountStars);
};
const handleProfile = (err, profile) 
=> {
getRepos(profile.login, handleRepos);
};
getProfile("rizafahmi", handleProfile);
const handleCountStars = (err, stars) 
=> {
console.log(`Total stars: ${stars}`);
};
const handleRepos = (err, repos) 
=> {
countTotalStars(repos, handleCountStars);
};
const handleProfile = (err, profile) 
=> {
getRepos(profile.login, handleRepos);
};
getProfile("rizafahmi", handleProfile);
const handleCountStars = (err, stars) 
=> {
console.log(`Total stars: ${stars}`);
};
const handleRepos = (err, repos) 
=> {
countTotalStars(repos, handleCountStars);
};
const handleProfile = (err, profile) 
=> {
getRepos(profile.login, handleRepos);
};
getProfile("rizafahmi", handleProfile);
const handleCountStars = (err, stars) 
=> {
console.log(`Total stars: ${stars}`);
};
const handleRepos = (err, repos) 
=> {
countTotalStars(repos, handleCountStars);
};
const handleProfile = (err, profile) 
=> {
getRepos(profile.login, handleRepos);
};
getProfile("rizafahmi", handleProfile);

Recommended for you

Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing

Workshop JavaScript Testing. Frameworks. Client vs Server Testing. Jasmine. Chai. Nock. Sinon. Spec Runners: Karma. TDD. Code coverage. Building a testable JS app. Presentado por ing: Raúl Delgado y Mario García

visualengintestingjavascript
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP

Presentation made at GTA meetup in 2012-02-07. Object Calisthenics is a set of exercise rules to reach better code, maintainable, testable and readable.

object-oriented programmingphpobject calisthenics
Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8

JavaScript is one of the most popular skills in today’s job market. It allows you to create both client- and server-side applications quickly and easily. Having a solid understanding of this powerful and versatile language is essential to anyone who uses it. “Practical JavaScript Programming” does not only focus on best practices, but also introduces the fundamental concepts. This course will take you from JavaScript basics to advanced. You’ll learn about topics like Data Types, Functions, Events, AJAX and more.

javascriptjses6
Great! But it's hard to read/
write
THE Promise
Promise is...
“A Promise is a proxy for a value not
necessarily known when the promise
is created. It allows you to
associate handlers with an
asynchronous action's eventual
success value or failure reason.”
Mozilla Develpoer Network
Promise is...
A promise is an object that may produce
a single value some time in the future:
either a resolved value, or a reason that
it’s not resolved.
Eric Elliot

Recommended for you

Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)

Have you ever used PHP's built in reflection, only to find you can't do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren't loaded, so that you can modify them directly? Better Reflection is an awesome new library that uses magical time-warp techniques* (*actual magic or time-warp not guaranteed) to improve on PHP's built-in reflection by providing additional functionality. In this talk we'll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.

libraryphpreflection
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...

The document provides advice and best practices for writing code that lasts over time. It discusses improving code through practices like making it more comprehensible, flexible, tested, and refactorable. Specific techniques mentioned include object calisthenics exercises like limiting indentation levels and instance variables, using first class collections, and avoiding getters/setters. The document emphasizes continuously improving code through practices like reading and sharing code with others.

Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town

As presented at Dutch PHP Conference 2015, an introduction to command buses, how to implement your own in PHP and why they're both useful but unimportant.

phpcommand busservice layers
getProfile("rizafahmi")
.then(profile 
=> {
return getRepos(profile.login)})
.then(repos 
=> {
return countTotalStars(repos)})
.catch(err 
=> {
console.error(err) })
getProfile("rizafahmi")
.then(profile 
=> {
return getRepos(profile.login)})
.then(repos 
=> {
return countTotalStars(repos)})
.catch(err 
=> {
console.error(err) })
getProfile("rizafahmi")
.then(profile 
=> {
return getRepos(profile.login)})
.then(repos 
=> {
return countTotalStars(repos)})
.catch(err 
=> {
console.error(err) })
getProfile("rizafahmi")
.then(profile 
=> getRepos(profile.login))
.then(repos 
=> countTotalStars(repos))
.catch(err 
=> {
console.error(err);
});

Recommended for you

循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし

The document discusses various techniques in Perl for dealing with reference cycles and memory leaks caused by strong references, including using weak references, extracting needed data from objects before destroying them, and passing objects into subroutines to avoid capturing them. It also discusses analogous techniques used in Objective-C like weak references and guard objects to break cycles.

perl leak
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm

In a world where users have ever higher expectations from the apps they use, having data always available, even when the device is offline, has become increasingly important. In this talk you will learn how thinking "offline first" not only makes your app architecture better but also result in cleaner code and happier users. I will introduce Realm, a new database for easy persistence, and demonstrate how it enables truly reactive UI's by fitting seamlessly into the standard network stack of Retrofit and RxJava. Finally we will take a look at the new Realm Mobile Platform, which provides real-time synchronization between devices, enabling features previously out of reach for many development teams.

androidrealmdatabase
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript

The document provides an introduction to asynchronous JavaScript. It discusses callbacks and their disadvantages like callback hell. Promises are introduced as a better way to handle asynchronous code by making it easier to write and chain asynchronous operations. Async/await is described as syntactic sugar that allows asynchronous code to be written more readably in a synchronous style using await and try/catch. Key aspects like the event loop, microtask queue, and Promise methods like all and race are explained. Overall the document aims to help understand what makes asynchronous code different and newer methods like promises and async/await that improve handling asynchronous operations in JavaScript.

javascriptcodeconference
BUUUUUTTTTTT.....
$riza_profile = get_profile("rizafahmi");
$riza_repos = get_repos($riza_profile[“login"]);
$riza_stars = count_total_stars($riza_repos);
riza_profile = get_profile("rizafahmi")
riza_repos = get_repos(riza_profile[“login"])
riza_stars = count_total_stars(riza_repos)
Async/await

Recommended for you

Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript

Jasmine is a BDD framework for testing JavaScript code. It does not depend on other frameworks and does not require a DOM. Jasmine uses specs, expectations, suites, and matchers to define tests and make assertions. It also supports features for testing asynchronous code and spying on functions. Jasmine provides tools like spies, stubs, fakes, and mocks to help test code behavior.

software testingjavascript
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript

Basic JavaScript Object Oriented Best Practices Library MVC Performance Debug Documentation Tools

javascriptmvctools
JS Fest 2019 Node.js Antipatterns
JS Fest 2019 Node.js AntipatternsJS Fest 2019 Node.js Antipatterns
JS Fest 2019 Node.js Antipatterns

Structure and architecture, API, security, asynchronity, routing, middlewares, data access, memory, cpu, state management, etc.

node.jsnodejsfest
(async () 
=> {
const riza_profile = await getProfile("rizafahmi");
const riza_repos = await getRepos(riza_profile.login);
const riza_stars = countTotalStars(riza_repos);
})();
(async () 
=> {
const riza_profile = await getProfile("rizafahmi");
const riza_repos = await getRepos(riza_profile.login);
const riza_stars = countTotalStars(riza_repos);
})();
const countStars = async () 
=> {
const riza_profile = await getProfile("rizafahmi");
const riza_repos = await getRepos(riza_profile.login);
const riza_stars = countTotalStars(riza_repos);
};
countStars();
const countStars = async () 
=> {
const riza_profile = await getProfile("rizafahmi");
const riza_repos = await getRepos(riza_profile.login);
const riza_stars = countTotalStars(riza_repos);
};
countStars();

Recommended for you

Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World

In a world where users have ever higher expectations from the apps they use, having data always available, even when the device is offline has become increasingly important. In this talk we will go through different ways of saving data on the phone and introduce Realm as a replacement for SQLite and ORM's. Through an example app it will be demonstrated that thinking "Offline first" not only affects your apps architecture for the better, but also results in happier users.

databaseandroidrealm
ERRest
ERRestERRest
ERRest

Learn what's new in Project Wonder's ERRest framework. Also, see some tips about security and versioning for your REST services, and learn how you can use HTML routing to build Web apps with ERRest.

webobjectsrestfulproject wonder
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails

My attempts to make my experience developing Play 2 web-applications (in Scala) more Rails-like. I show 3 frameworks employed that draw nearer to the Ruby/Rails spirit than Play's default offerings.

playrailsframework
Buuuuuttttt....
Somebody said error handling in
async/await is ugly....
Option #1
Make sure errors don't happen
#problemsolved
Option #2
try/catch
(async () 
=> {
try {
const profile = await getProfile("rizafahmi");
const repos = await getRepos(profile.data.items[0].login);
const stars = countTotalStars(repos.data);
console.log(`Total stars: ${stars}`);
} catch (e) {
console.error(e);
}
})();

Recommended for you

How to React Native
How to React NativeHow to React Native
How to React Native

This document provides an overview of how to build applications with React Native. It discusses React Native's core components like React, ReactDOM and React Native. It also covers topics like JavaScript implementation, building components, styles, platform specific code, animations, navigation libraries and working with data using Redux.

react nativereactredux-saga
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal

The document discusses the lifecycle of code under test, including defining inputs and outputs, initial testing with positive and negative cases, handling bugs, refactoring code, adding abstraction, how future work may affect tests, and handling legacy code. It provides an example of a function to add two strings, injecting a bug, and walking through testing the code at different stages of the lifecycle from initial testing to refactoring and abstraction.

qaoth2020testing
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7

The document summarizes an upcoming Java user group meeting to discuss Java 7 features. It will cover new language features in Java 7 like binary literals, string switches, and try-with-resources statements. It will also cover parallel programming enhancements like Fork/Join and NIO.2. The meeting will include hands-on demos of Java 7 features and a discussion of upcoming Java 8 features. Refreshments will be provided by meeting sponsor Ovialis.

nantesjugjava7java
Option #3
Handle error when you call it
(async () 
=> {
const profile = await getProfile("rizafahmi").catch(e 
=> console.error(e));
const repos = await getRepos(profile.data.items[0].login).catch(e 
=>
console.error(e)
);
const stars = countTotalStars(repos.data);
console.log(`Total stars: ${stars}`);
})();
(async () 
=> {
const profile = await getProfile("rizafahmi").catch(e 
=> console.error(e));
const repos = await getRepos(profile.data.items[0].login).catch(e 
=>
console.error(e)
);
const stars = countTotalStars(repos.data);
console.log(`Total stars: ${stars}`);
})();
(async () 
=> {
const profile = await getProfile("rizafahmi").catch(e 
=> console.error(e));
const repos = await getRepos(profile.data.items[0].login).catch(e 
=>
console.error(e)
);
const stars = countTotalStars(repos.data);
console.log(`Total stars: ${stars}`);
})();

Recommended for you

Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns

The document discusses different patterns for handling asynchronous code in JavaScript: callbacks, promises, and AMD (Asynchronous Module Definition). It outlines issues with nested callbacks and inflexible APIs. Promises and AMD aim to address these by allowing composition of asynchronous operations and defining module dependencies. The document provides examples of implementing PubSub with events, making and piping promises, and using AMD to load dependencies asynchronously. It concludes that callbacks should generally be avoided in favor of promises or AMD for asynchronous code.

javascript
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal

There are more smart people building software now than there have been at any point in the past, which means that it's more important than ever to stay on top of new developments, libraries, frameworks, and everything else. To really take advantage of this wealth of innovation, however, you've got to look beyond your normal community -- what's going on in Python? And how can we use that to make our Ruby lives easier? In this session, we'll explore that question. We'll look at actual examples of code and concepts borrowed and reimplemented to form a better idea of when it's appropriate and when it'll fall flat.

coderuby
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet

The document discusses FuseJS, a JavaScript framework that aims to improve performance and compatibility across browsers. It includes sandboxed native objects to prevent namespace pollution, modular builds, and various selector engines. It also details optimizations for quirks mode, events, caching, and performance benchmarks showing FuseJS has lower execution times than other frameworks.

sandboxed nativesfusejscss selector engines
Option #4
Higher Order Func!ons
const handleError = fn 
=> {
return (

...params) 
=> {
return fn(

...params).catch(e 
=> {
console.error(e);
});
};
};
const safeGetProfile = handleError(getProfile);
(async () 
=> {
const riza = await safeGetProfile("rizafahmi");
console.log(riza.data.items[0].login);
})();
const handleError = fn 
=> {
return (

...params) 
=> {
return fn(

...params).catch(e 
=> {
console.error(e);
});
};
};
const safeGetProfile = handleError(getProfile);
(async () 
=> {
const riza = await safeGetProfile("rizafahmi");
console.log(riza.data.items[0].login);
})();
const handleError = fn 
=> {
return (

...params) 
=> {
return fn(

...params).catch(e 
=> {
console.error(e);
});
};
};
const safeGetProfile = handleError(getProfile);
(async () 
=> {
const riza = await safeGetProfile("rizafahmi");
console.log(riza.data.items[0].login);
})();

Recommended for you

Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...

This talk takes a deep dive into asynchronous programming patterns and practices, with an emphasis on the promise pattern. We go through the basics of the event loop, highlighting the drawbacks of asynchronous programming in a naive callback style. Fortunately, we can use the magic of promises to escape from callback hell with a powerful and unified interface for async APIs. Finally, we take a quick look at the possibilities for using coroutines both in current and future (ECMAScript Harmony) JavaScript.

javascriptpromisesajax
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM

The document discusses various approaches for leveraging parallelism and concurrency including multithreading, fork/join, actors, dataflow, and software transactional memory. It notes that while multithreading is challenging, other approaches like actors, dataflow, and STM can allow for writing concurrency-agnostic code. It promotes the GPars library for its implementations of various parallel and concurrent programming abstractions in Java and Groovy.

concurrency jvm java groovy scala clojure actors a
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016

Redux-observable allows combining RxJS and Redux by introducing Epics. Epics are Observable streams that handle asynchronous logic in response to Redux actions. This avoids callback hell and enables features like cancellation. An Epic takes an action stream, performs asynchronous operations like AJAX calls using RxJS, and dispatches result actions. This keeps Redux synchronous while managing complex async flows in a declarative and reusable way.

rxjsjavascriptreact
const safeGetProfile = handleError(getProfile);
(async () 
=> {
const riza = await safeGetProfile("rizafahmi");
console.log(riza.data.items[0].login);
})();
const handleError = fn 
=> (

...params) 
=> fn(

...params).catch(console.error(e));
“If just using callback you can solving
your problem, why you have push
your self using Promise?!”
Hengki Sihombing, CTO, Co-Founder Urbanhire
async/await Revisited
And I’m done!
github.com/rizafahmi/callback-promise-async-revisited
slideshare.net/rizafahmi
riza@hack!v8.com
ceritanyadeveloper.com

Recommended for you

Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks

Why is data validation important? What are effective ways to ensure data is valid? In this session we'll explore how data validation is directly linked to security, stability and developer productivity when dealing with untrusted or unknown data sources. We'll discuss the dangers of code that does not validate its data - everything from injection to DOS attacks. We'll go hands on with joi (https://github.com/hapijs/joi) and Express (http://expressjs.com/) to see how data validation can make code easier to work with. No more "Uncaught ReferenceError" or if null checks littered around the code base. In the end, we'll see how code can be secure, stable and magically awesome to work with.

node.js interactive north america
Node.js
Node.jsNode.js
Node.js

This document provides an introduction and overview of Node.js. It discusses that Node.js is asynchronous and event-driven, uses non-blocking I/O, and is well-suited for data-intensive real-time applications that run across distributed devices. It also provides instructions on getting started with Node.js, including installing it, basic usage like importing modules and writing files, how to create a simple web server, working with event-driven libraries, and popular Node.js projects like Express and Socket.IO.

nodejavascriptphillyjs
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks

Why is data validation important? What are effective ways to ensure data is valid? In this session we’ll explore how data validation is directly linked to security, stability and developer productivity when dealing with untrusted or unknown data sources. We’ll discuss the dangers of code that does not validate its data - everything from injection to DOS attacks. We’ll go hands on with joi (https://github.com/hapijs/joi) and Express (http://expressjs.com/) to see how data validation can make code easier to work with. No more "Uncaught ReferenceError" or if null checks littered around the code base. In the end, we’ll see how code can be secure, stable and magically awesome to work with.

More Related Content

What's hot

스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내
Jung Kim
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
Mark Baker
 
Ruby closures, how are they possible?
Ruby closures, how are they possible?Ruby closures, how are they possible?
Ruby closures, how are they possible?
Carlos Alonso Pérez
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
Rafael Dohms
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
Aaron Huang
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
Ross Tuck
 
PHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an AnalysisPHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an Analysis
Positive Hack Days
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Mail.ru Group
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
Rafael Dohms
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
RameshNair6
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
Rafael Dohms
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Jung Kim
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
Visual Engineering
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
Guilherme Blanco
 
Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8
Wilson Su
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
Rafael Dohms
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
Ross Tuck
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
Masahiro Honma
 

What's hot (19)

스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내스위프트를 여행하는 히치하이커를 위한 스타일 안내
스위프트를 여행하는 히치하이커를 위한 스타일 안내
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Ruby closures, how are they possible?
Ruby closures, how are they possible?Ruby closures, how are they possible?
Ruby closures, how are they possible?
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
PHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an AnalysisPHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an Analysis
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
 
Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 

Similar to async/await Revisited

Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
Christian Melchior
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
Luis Alfredo Porras Páez
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
Tarek Yehia
 
JS Fest 2019 Node.js Antipatterns
JS Fest 2019 Node.js AntipatternsJS Fest 2019 Node.js Antipatterns
JS Fest 2019 Node.js Antipatterns
Timur Shemsedinov
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
Christian Melchior
 
ERRest
ERRestERRest
ERRest
WO Community
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
Sebastian Nozzi
 
How to React Native
How to React NativeHow to React Native
How to React Native
Dmitry Ulyanov
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
QA or the Highway
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
Sébastien Prunier
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
TrevorBurnham
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
Ben Scofield
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
johndaviddalton
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
Vaclav Pech
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
NodejsFoundation
 
Node.js
Node.jsNode.js
Node.js
Mat Schaffer
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
NodejsFoundation
 

Similar to async/await Revisited (20)

Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
JS Fest 2019 Node.js Antipatterns
JS Fest 2019 Node.js AntipatternsJS Fest 2019 Node.js Antipatterns
JS Fest 2019 Node.js Antipatterns
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
ERRest
ERRestERRest
ERRest
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 
Node.js
Node.jsNode.js
Node.js
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 

More from Riza Fahmi

Membangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan PhoenixMembangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan Phoenix
Riza Fahmi
 
Berbagai Pilihan Karir Developer
Berbagai Pilihan Karir DeveloperBerbagai Pilihan Karir Developer
Berbagai Pilihan Karir Developer
Riza Fahmi
 
Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020
Riza Fahmi
 
Remote Working/Learning
Remote Working/LearningRemote Working/Learning
Remote Working/Learning
Riza Fahmi
 
How to learn programming
How to learn programmingHow to learn programming
How to learn programming
Riza Fahmi
 
Rapid App Development with AWS Amplify
Rapid App Development with AWS AmplifyRapid App Development with AWS Amplify
Rapid App Development with AWS Amplify
Riza Fahmi
 
Menguak Misteri Module Bundler
Menguak Misteri Module BundlerMenguak Misteri Module Bundler
Menguak Misteri Module Bundler
Riza Fahmi
 
Beberapa Web API Menarik
Beberapa Web API MenarikBeberapa Web API Menarik
Beberapa Web API Menarik
Riza Fahmi
 
MVP development from software developer perspective
MVP development from software developer perspectiveMVP development from software developer perspective
MVP development from software developer perspective
Riza Fahmi
 
Ekosistem JavaScript di Indonesia
Ekosistem JavaScript di IndonesiaEkosistem JavaScript di Indonesia
Ekosistem JavaScript di Indonesia
Riza Fahmi
 
Perkenalan ReasonML
Perkenalan ReasonMLPerkenalan ReasonML
Perkenalan ReasonML
Riza Fahmi
 
How I Generate Idea
How I Generate IdeaHow I Generate Idea
How I Generate Idea
Riza Fahmi
 
Strategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop SlideStrategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop Slide
Riza Fahmi
 
Lesson Learned from Prolific Developers
Lesson Learned from Prolific DevelopersLesson Learned from Prolific Developers
Lesson Learned from Prolific Developers
Riza Fahmi
 
Clean Code JavaScript
Clean Code JavaScriptClean Code JavaScript
Clean Code JavaScript
Riza Fahmi
 
The Future of AI
The Future of AIThe Future of AI
The Future of AI
Riza Fahmi
 
Chrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take AwaysChrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take Aways
Riza Fahmi
 
Modern Static Site with GatsbyJS
Modern Static Site with GatsbyJSModern Static Site with GatsbyJS
Modern Static Site with GatsbyJS
Riza Fahmi
 
Introduction to ReasonML
Introduction to ReasonMLIntroduction to ReasonML
Introduction to ReasonML
Riza Fahmi
 
Machine learning with py torch
Machine learning with py torchMachine learning with py torch
Machine learning with py torch
Riza Fahmi
 

More from Riza Fahmi (20)

Membangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan PhoenixMembangun Aplikasi Web dengan Elixir dan Phoenix
Membangun Aplikasi Web dengan Elixir dan Phoenix
 
Berbagai Pilihan Karir Developer
Berbagai Pilihan Karir DeveloperBerbagai Pilihan Karir Developer
Berbagai Pilihan Karir Developer
 
Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020Web dan Progressive Web Apps di 2020
Web dan Progressive Web Apps di 2020
 
Remote Working/Learning
Remote Working/LearningRemote Working/Learning
Remote Working/Learning
 
How to learn programming
How to learn programmingHow to learn programming
How to learn programming
 
Rapid App Development with AWS Amplify
Rapid App Development with AWS AmplifyRapid App Development with AWS Amplify
Rapid App Development with AWS Amplify
 
Menguak Misteri Module Bundler
Menguak Misteri Module BundlerMenguak Misteri Module Bundler
Menguak Misteri Module Bundler
 
Beberapa Web API Menarik
Beberapa Web API MenarikBeberapa Web API Menarik
Beberapa Web API Menarik
 
MVP development from software developer perspective
MVP development from software developer perspectiveMVP development from software developer perspective
MVP development from software developer perspective
 
Ekosistem JavaScript di Indonesia
Ekosistem JavaScript di IndonesiaEkosistem JavaScript di Indonesia
Ekosistem JavaScript di Indonesia
 
Perkenalan ReasonML
Perkenalan ReasonMLPerkenalan ReasonML
Perkenalan ReasonML
 
How I Generate Idea
How I Generate IdeaHow I Generate Idea
How I Generate Idea
 
Strategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop SlideStrategi Presentasi Untuk Developer Workshop Slide
Strategi Presentasi Untuk Developer Workshop Slide
 
Lesson Learned from Prolific Developers
Lesson Learned from Prolific DevelopersLesson Learned from Prolific Developers
Lesson Learned from Prolific Developers
 
Clean Code JavaScript
Clean Code JavaScriptClean Code JavaScript
Clean Code JavaScript
 
The Future of AI
The Future of AIThe Future of AI
The Future of AI
 
Chrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take AwaysChrome Dev Summit 2018 - Personal Take Aways
Chrome Dev Summit 2018 - Personal Take Aways
 
Modern Static Site with GatsbyJS
Modern Static Site with GatsbyJSModern Static Site with GatsbyJS
Modern Static Site with GatsbyJS
 
Introduction to ReasonML
Introduction to ReasonMLIntroduction to ReasonML
Introduction to ReasonML
 
Machine learning with py torch
Machine learning with py torchMachine learning with py torch
Machine learning with py torch
 

Recently uploaded

Measuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at TwitterMeasuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at Twitter
ScyllaDB
 
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Bert Blevins
 
Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
Awais Yaseen
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
Toru Tamaki
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
Manual | Product | Research Presentation
Manual | Product | Research PresentationManual | Product | Research Presentation
Manual | Product | Research Presentation
welrejdoall
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 

Recently uploaded (20)

Measuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at TwitterMeasuring the Impact of Network Latency at Twitter
Measuring the Impact of Network Latency at Twitter
 
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
 
Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
Manual | Product | Research Presentation
Manual | Product | Research PresentationManual | Product | Research Presentation
Manual | Product | Research Presentation
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 

async/await Revisited

  • 1. Async/Await Revisited We will talk about callback, promise and async/await.
  • 4. JS waits for nobody
  • 5. JS will move on without waiting some process to finish.
  • 6. Async Example • Ajax call • Access user's webcam • Resize image
  • 7. How we deal with it?
  • 9. “Callbacks are func!ons that you pass as arguments to be invoked when the callee has finished its job.” Callback is... Eric Elliot
  • 10. getProfile("rizafahmi", (err, profile) => { getRepos(profile.login, (err, repos) => { countTotalStars(repos, (err, stars) => { // count the stars }); }); });
  • 11. getProfile("rizafahmi", (err, profile) => { getRepos(profile.login, (err, repos) => { countTotalStars(repos, (err, stars) => { // count the stars }); }); });
  • 12. getProfile("rizafahmi", (err, profile) => { getRepos(profile.login, (err, repos) => { countTotalStars(repos, (err, stars) => { // count the stars }); }); });
  • 13. const handleCountStars = (err, stars) => { console.log(`Total stars: ${stars}`); }; const handleRepos = (err, repos) => { countTotalStars(repos, handleCountStars); }; const handleProfile = (err, profile) => { getRepos(profile.login, handleRepos); }; getProfile("rizafahmi", handleProfile);
  • 14. const handleCountStars = (err, stars) => { console.log(`Total stars: ${stars}`); }; const handleRepos = (err, repos) => { countTotalStars(repos, handleCountStars); }; const handleProfile = (err, profile) => { getRepos(profile.login, handleRepos); }; getProfile("rizafahmi", handleProfile);
  • 15. const handleCountStars = (err, stars) => { console.log(`Total stars: ${stars}`); }; const handleRepos = (err, repos) => { countTotalStars(repos, handleCountStars); }; const handleProfile = (err, profile) => { getRepos(profile.login, handleRepos); }; getProfile("rizafahmi", handleProfile);
  • 16. const handleCountStars = (err, stars) => { console.log(`Total stars: ${stars}`); }; const handleRepos = (err, repos) => { countTotalStars(repos, handleCountStars); }; const handleProfile = (err, profile) => { getRepos(profile.login, handleRepos); }; getProfile("rizafahmi", handleProfile);
  • 17. Great! But it's hard to read/ write
  • 19. Promise is... “A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason.” Mozilla Develpoer Network
  • 20. Promise is... A promise is an object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved. Eric Elliot
  • 21. getProfile("rizafahmi") .then(profile => { return getRepos(profile.login)}) .then(repos => { return countTotalStars(repos)}) .catch(err => { console.error(err) })
  • 22. getProfile("rizafahmi") .then(profile => { return getRepos(profile.login)}) .then(repos => { return countTotalStars(repos)}) .catch(err => { console.error(err) })
  • 23. getProfile("rizafahmi") .then(profile => { return getRepos(profile.login)}) .then(repos => { return countTotalStars(repos)}) .catch(err => { console.error(err) })
  • 24. getProfile("rizafahmi") .then(profile => getRepos(profile.login)) .then(repos => countTotalStars(repos)) .catch(err => { console.error(err); });
  • 26. $riza_profile = get_profile("rizafahmi"); $riza_repos = get_repos($riza_profile[“login"]); $riza_stars = count_total_stars($riza_repos);
  • 27. riza_profile = get_profile("rizafahmi") riza_repos = get_repos(riza_profile[“login"]) riza_stars = count_total_stars(riza_repos)
  • 29. (async () => { const riza_profile = await getProfile("rizafahmi"); const riza_repos = await getRepos(riza_profile.login); const riza_stars = countTotalStars(riza_repos); })();
  • 30. (async () => { const riza_profile = await getProfile("rizafahmi"); const riza_repos = await getRepos(riza_profile.login); const riza_stars = countTotalStars(riza_repos); })();
  • 31. const countStars = async () => { const riza_profile = await getProfile("rizafahmi"); const riza_repos = await getRepos(riza_profile.login); const riza_stars = countTotalStars(riza_repos); }; countStars();
  • 32. const countStars = async () => { const riza_profile = await getProfile("rizafahmi"); const riza_repos = await getRepos(riza_profile.login); const riza_stars = countTotalStars(riza_repos); }; countStars();
  • 33. Buuuuuttttt.... Somebody said error handling in async/await is ugly....
  • 34. Option #1 Make sure errors don't happen #problemsolved
  • 36. (async () => { try { const profile = await getProfile("rizafahmi"); const repos = await getRepos(profile.data.items[0].login); const stars = countTotalStars(repos.data); console.log(`Total stars: ${stars}`); } catch (e) { console.error(e); } })();
  • 37. Option #3 Handle error when you call it
  • 38. (async () => { const profile = await getProfile("rizafahmi").catch(e => console.error(e)); const repos = await getRepos(profile.data.items[0].login).catch(e => console.error(e) ); const stars = countTotalStars(repos.data); console.log(`Total stars: ${stars}`); })();
  • 39. (async () => { const profile = await getProfile("rizafahmi").catch(e => console.error(e)); const repos = await getRepos(profile.data.items[0].login).catch(e => console.error(e) ); const stars = countTotalStars(repos.data); console.log(`Total stars: ${stars}`); })();
  • 40. (async () => { const profile = await getProfile("rizafahmi").catch(e => console.error(e)); const repos = await getRepos(profile.data.items[0].login).catch(e => console.error(e) ); const stars = countTotalStars(repos.data); console.log(`Total stars: ${stars}`); })();
  • 42. const handleError = fn => { return ( ...params) => { return fn( ...params).catch(e => { console.error(e); }); }; }; const safeGetProfile = handleError(getProfile); (async () => { const riza = await safeGetProfile("rizafahmi"); console.log(riza.data.items[0].login); })();
  • 43. const handleError = fn => { return ( ...params) => { return fn( ...params).catch(e => { console.error(e); }); }; }; const safeGetProfile = handleError(getProfile); (async () => { const riza = await safeGetProfile("rizafahmi"); console.log(riza.data.items[0].login); })();
  • 44. const handleError = fn => { return ( ...params) => { return fn( ...params).catch(e => { console.error(e); }); }; }; const safeGetProfile = handleError(getProfile); (async () => { const riza = await safeGetProfile("rizafahmi"); console.log(riza.data.items[0].login); })();
  • 45. const safeGetProfile = handleError(getProfile); (async () => { const riza = await safeGetProfile("rizafahmi"); console.log(riza.data.items[0].login); })(); const handleError = fn => ( ...params) => fn( ...params).catch(console.error(e));
  • 46. “If just using callback you can solving your problem, why you have push your self using Promise?!” Hengki Sihombing, CTO, Co-Founder Urbanhire