GithubHelp home page GithubHelp logo

eltoroit / etasyncjs Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 4.0 267 KB

Asynchronous JavaScript using Salesforce Lightning Web Components (LWC)

Home Page: https://www.linkedin.com/pulse/asynchronous-javascript-using-salesforce-lightning-web-eltoroit-/

Shell 20.06% HTML 25.09% JavaScript 54.85%

etasyncjs's Introduction

Asynchronous JavaScript using Salesforce Lightning Web Components (LWC)

Asynchronous JavaScript using Salesforce Lightning Web Components (LWC)

This week I was teaching a class on LWC in Chicago, IL and the students asked me about asynchronous JavaScript. Being such an important topic, I built a simple demo that I have cleaned a bit to explains the different ways to work with Asynchronous JavaScript from LWC.

This is the idea behind this simple demo: We have three operations (A, B, C) which can take any amount of time to complete, therefore we need to execute them asynchronously. As a matter of fact, you control when each of these processes finishes and in which order by toggling their button on the screen, or you can fail the operations to see the exception behavior.

I have created a repo for this SFDX project with the LWC code (click here to view it)

Visit Repo

The operations can be done in three different scenarios:

  • Any Order: The operations run in parallel and we can take some action when any of those finish in the order they are completing. The code can be written with Callbacks anyOrderCallback(), Promises anyOrderPromises() but Async/Await can’t be used here.
  • Serial: The operations have to be completed in serial mode. We must complete A, before starting B, and finish B before starting C. The operation will only complete if the correct toggle is used. The code can be written with Callbacks serialCallback(), Promises serialPromises() or Async/Await serialAsyncAwait().
  • After All: This last operation can only be done with Promises afterAllPromises(). The idea is that we will wait until all the operations have completed, regardless of the order. This is a good technique if you want to download some files for example, and we do not care about the order in which they arrive, we only care that all of them have arrived.

I will now wait asynchronously for your feedback and comments :-)

etasyncjs's People

Contributors

eltoroit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.