Skip to content

Instantly share code, notes, and snippets.

@dbayarchyk
Last active October 1, 2019 13:23
Show Gist options
  • Select an option

  • Save dbayarchyk/484b49cfe35659c5985c8d93dd6a8bc9 to your computer and use it in GitHub Desktop.

Select an option

Save dbayarchyk/484b49cfe35659c5985c8d93dd6a8bc9 to your computer and use it in GitHub Desktop.

Revisions

  1. dbayarchyk revised this gist Oct 1, 2019. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions regularAsyncAwaitExample.js
    Original file line number Diff line number Diff line change
    @@ -8,16 +8,12 @@ async function fetchAndUpdatePosts() {
    }

    if (!posts) {
    return null;
    return;
    }

    let updatedPosts;

    try {
    updatedPosts = await updatePosts();
    await updatePosts();
    } catch {
    console.log('error in updating posts');
    }

    return updatedPosts || null;
    }
  2. dbayarchyk revised this gist Oct 1, 2019. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions regularAsyncAwaitExample.js
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,16 @@ async function fetchAndUpdatePosts() {
    }

    if (!posts) {
    return;
    return null;
    }

    let updatedPosts;

    try {
    await updatePosts();
    updatedPosts = await updatePosts();
    } catch {
    console.log('error in updating posts');
    }

    return updatedPosts || null;
    }
  3. dbayarchyk revised this gist Oct 1, 2019. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions regularAsyncAwaitExample.js
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,4 @@ async function fetchAndUpdatePosts() {
    } catch {
    console.log('error in updating posts');
    }

    console.log('updated posts successfully');
    }
  4. dbayarchyk revised this gist Oct 1, 2019. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions regularAsyncAwaitExample.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,10 @@ async function fetchAndUpdatePosts() {
    console.log('error in fetching posts');
    }

    if (!posts) {
    return;
    }

    try {
    await updatePosts();
    } catch {
  5. dbayarchyk revised this gist Oct 1, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions regularAsyncAwaitExample.js
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,6 @@ async function fetchAndUpdatePosts() {
    } catch {
    console.log('error in updating posts');
    }

    console.log('updated posts successfully');
    }
  6. dbayarchyk revised this gist Oct 1, 2019. No changes.
  7. dbayarchyk revised this gist Oct 1, 2019. 2 changed files with 15 additions and 15 deletions.
    15 changes: 0 additions & 15 deletions promiseChain.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +0,0 @@
    function doSomething() {
    fetchPosts()
    .then((items) => {
    updatePosts()
    .then(() => {
    console.log('updated posts successfully');
    })
    .catch(() => {
    console.log('error in updating posts');
    });
    })
    .catch(() => {
    console.log('error in fetching posts');
    });
    }
    15 changes: 15 additions & 0 deletions regularAsyncAwaitExample.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    async function fetchAndUpdatePosts() {
    let posts;

    try {
    posts = await fetchPosts();
    } catch {
    console.log('error in fetching posts');
    }

    try {
    await updatePosts();
    } catch {
    console.log('error in updating posts');
    }
    }
  8. dbayarchyk revised this gist Oct 1, 2019. No changes.
  9. dbayarchyk revised this gist Oct 1, 2019. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions promiseChain.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,15 @@
    async function doSomthing() {

    function doSomething() {
    fetchPosts()
    .then((items) => {
    updatePosts()
    .then(() => {
    console.log('updated posts successfully');
    })
    .catch(() => {
    console.log('error in updating posts');
    });
    })
    .catch(() => {
    console.log('error in fetching posts');
    });
    }
  10. dbayarchyk created this gist Oct 1, 2019.
    3 changes: 3 additions & 0 deletions promiseChain.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    async function doSomthing() {

    }