Handling Asynchrony with Vue Composition API and vue-concurrency

Handling Asynchrony with Vue Composition API and vue-concurrency

Part 2 — canceling, throttling, debouncing, polling. In the previous article, I talked about promises and handling async state. This article will point towards another weak point of promises: lack of cancelation.

In the previous article, I talked about promises and handling async state. This article will point towards another weak point of promises: lack of cancelation.

It’s easy to think that you have no need for cancelation. Paradoxically, because with the current default tools in JavaScript cancelation is hard, it’s not often talked about and recommended. But there indeed are use cases when cancelation is a powerful tool and not just for some advanced use cases, but also in common features such as debouncing and polling or just to make asynchronous logic overall more safe. You just need the right tool.

Promises are not cancellable and therefore you also can’t cancel an async function. One way to go around this is to make use of generators. Generator functions, like async functions, have a special syntax.

function myFun * () {
  yield foo();
  return 'bar';
}

Instead of async we mark the function with * and instead of await we write yield . But then generator functions are more flexible — their behavior is to a big degree defined by the consumer they are passed into. You can create yuor own handler of generator functions but most commonly you’d just rely on a 3rd party library. For example CAF — Cancellable Async Flows. Generator functions passed into CAF start to behave like async functions — yielding waits for promise resolution. But on top of that, it’s possible to [cancel](https://vue-concurrency.netlify.app/cancellation/#cancelation)``() and abort the execution early.

vue-concurrency takes use of CAF and wraps the whole logic into a handy reactive object: Task

javascript web-development front-end-development vuejs programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Dedicated VueJS Developers

Want to Hire VueJS Developer to develop an amazing app? **[Hire Dedicated VueJS Developers](https://hourlydeveloper.io/hire-dedicated-vue-js-developer/ "Hire Dedicated VueJS Developers")** on the contract (time/project) basis providing regular...

Top 19 Front-End Web Development Tools to Consider in 2020

In this post, we are putting curated list of top tools with key features and download links "Top 19 Front End Web Development Tools to Consider in 2020"

5 JavaScript Projects You Should Build As a Front-End Developer

5 JavaScript Projects You Should Build As a Front-End Developer: Brochure website; A blog template with HTML and CSS; Web application using an API; An eCommerce shopping cart; Personal portfolio

Top 6 Productivity Tools for Front-end Developers

Today I wanted to share with you the tools I daily use to increase my productivity as a front-end developer. 6 tools to increase your productivity as a Front-end developer.

Top 9 Open source JavaScript frameworks for front-end web development

About a decade ago, the JavaScript developer community began to witness fierce battles emerging among JavaScript frameworks. In this article, I will introduce some of the most well-known of these frameworks. And it's important to note that these are all open source JavaScript projects, meaning that you can freely utilize them under an open source license and even contribute to the source code and communities.