Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Functional Programming with TypeScript

You're reading from   Hands-On Functional Programming with TypeScript Explore functional and reactive programming to create robust and testable TypeScript applications

Arrow left icon
Product type Paperback
Published in Jan 2019
Publisher Packt
ISBN-13 9781788831437
Length 210 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 Jansen Jansen
Author Profile Icon Jansen
Jansen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Functional Programming Fundamentals FREE CHAPTER 2. Mastering Functions 3. Mastering Asynchronous Programming 4. The Runtime – The Event Loop and the this Operator 5. The Runtime – Closures and Prototypes 6. Functional Programming Techniques 7. Category Theory 8. Immutability, Optics, and Laziness 9. Functional-Reactive Programming 10. Real-World Functional Programming 11. Functional Programming Learning Road Map 12. Directory of TypeScript Functional Programming Libraries 13. Other Books You May Enjoy

Asynchronous functions – async and await

Asynchronous functions are a TypeScript feature that arrived with the TypeScript 1.6 release. Developers can use the await keyword to wait for an asynchronous operation to be completed without blocking the normal execution of the program.

Using asynchronous functions helps to increase the readability of a piece of code when compared with the use of promises or callbacks but, technically, we can achieve the same features using both promises and asynchronous functions.

Let's take a look at a basic async/await example:

let p = Promise.resolve(3);

async function fn(): Promise<number> {
var i = await p; // 3
return 1 + i; // 4
}

fn().then((r) => console.log(r)); // 4

The preceding code snippet declares a promise named p. This promise represents a future result. As we can see, the fn function is preceded by the async keyword...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime