Skip to content

async-calls#1

Open
mariailoaie wants to merge 1 commit into
masterfrom
mzanfirescu/async-calls
Open

async-calls#1
mariailoaie wants to merge 1 commit into
masterfrom
mzanfirescu/async-calls

Conversation

@mariailoaie

Copy link
Copy Markdown
Collaborator

Added some async calls examples

@ilazar

ilazar commented Jun 26, 2018

Copy link
Copy Markdown
Owner

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
Copy Markdown
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.

3 participants