Skip to content

Conversation

@mariailoaie
Copy link
Collaborator

Added some async calls examples

@ilazar
Copy link
Owner

ilazar commented Jun 26, 2018

As vrea sa folosim arrow functions.

Eu prezint aceste subiecte in general asa:

  1. setTimeout(fn, timeout), setTimeout(fn, 0), event queue

  2. callbacks

Definesc o fn

const task = ({ name, duration }, callback) => setTimeout(() => {
  if (duration > 100) { // max duration
    callback(new Error(`${name} timeout error`));
  }  else {
   callback(null, name);
  }
}, duration);

si apoi discut

  • chaining: a then b (if a fails, then b should not be executed)
  • callback hell: a then b then c (if any fails, the next tasks should not be executed)
  • parallel execution: a & b in parallel, then c (if one of a or b fails, the other should be cancelled and c should not execute)
  • cancellation techniques
  1. promises
  • refactor task using promises
  • the same topics discussed for callbacks
  1. async-await
  • refactor task using async await
  • the same topics discussed for callbacks & async-await

@mariailoaie
Copy link
Collaborator Author

Ok, o sa fac modificarile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants