This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Move this file to your neovim lua runtime path ie. ~/.config/nvim/lua/au.lua | |
-- | |
local cmd = vim.api.nvim_command | |
local function autocmd(this, event, spec) | |
local is_table = type(spec) == 'table' | |
local pattern = is_table and spec[1] or '*' | |
local action = is_table and spec[2] or spec | |
if type(action) == 'function' then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchStuff(data) { | |
try { | |
const page = data.page; | |
return fetchResults(page) | |
.then(res => res.results); | |
} catch (err) { | |
return Promise.reject(err); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetchStuff(data) { | |
const page = data.page; | |
const results = await fetchResults(page); | |
return res.results; | |
} | |
fetchStuff() | |
.catch(err => { /* handle error here */ }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchStuff(data) { | |
const page = data.page; | |
return fetchResults(page) | |
.then(res => res.results); | |
} | |
fetchStuff() | |
.catch(err => { /* handle error here */ }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function someFunc () { | |
// since we’re using await on someAsyncThing and the promise rejected | |
// this line will now throw it will throw `new Error('Boom')` | |
const result = await someAsyncThing(); | |
// this line will not execute | |
return result.value; | |
} | |
// externally we’ll get a rejected promise returned containing `Error('Boom')` | |
await someFunc(); | |
// But since we’re using await here, the rejected promise gets turned back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function () { | |
// someAsyncThing being a function that returns a promise | |
return someAsyncThing() | |
.then(result => result.value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function () { | |
// someAsyncThing being a function that returns a promise | |
const result = await someAsyncThing(); | |
return result.value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
throw new Error('Boom'); |
NewerOlder