Skip to content

Instantly share code, notes, and snippets.

View srebalaji's full-sized avatar
🎯
Focusing

Srebalaji Thirumalai srebalaji

🎯
Focusing
View GitHub Profile
@srebalaji
srebalaji / sample-promise-all-handle-rejection.js
Last active April 11, 2019 05:08
A sample promise all to handle rejections
const durations = [1000, 2000, 3000]
promises = durations.map((duration) => {
return timeOut(duration).catch(e => e) // Handling the error for each promise.
})
Promise.all(promises)
.then(response => console.log(response)) // ["Completed in 1000", "Rejected in 2000", "Completed in 3000"]
.catch(error => console.log(`Error in executing ${error}`))
@srebalaji
srebalaji / sample-promise-all-in-rejection.js
Last active March 23, 2019 07:50
A sample promise all with rejection
// A simple promise that resolves after a given time
const timeOut = (t) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (t === 2000) {
reject(`Rejected in ${t}`)
} else {
resolve(`Completed in ${t}`)
}
}, t)
@srebalaji
srebalaji / sample-promise-in-map.js
Last active March 23, 2019 07:43
A sample promise with map
// A simple promise that resolves after a given time
const timeOut = (t) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(`Completed in ${t}`)
}, t)
})
}
const durations = [1000, 2000, 3000]
@srebalaji
srebalaji / sample-promise.js
Created March 4, 2019 16:57
A simple JS file that explains Promise.all
// A simple promise that resolves after a given time
const timeOut = (t) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(`Completed in ${t}`)
}, t)
})
}
// Resolving a normal promise.
@srebalaji
srebalaji / Gemfile
Last active May 5, 2019 04:55
Pry plugins
pry-rescue
pry-nav
pry-rails
pry-stack_explorer
pry-theme
@srebalaji
srebalaji / .vimrc
Last active October 30, 2017 06:14
Vim configuration
set number
set noet ci pi sts=0 sw=4 ts=4
set cursorline
set showcmd
filetype indent on
set wildmenu
set lazyredraw
set showmatch
set incsearch
set hlsearch