Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created January 19, 2017 22:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ericelliott/2a1fa460e3e8330c5a2cad87acccb015 to your computer and use it in GitHub Desktop.
Save ericelliott/2a1fa460e3e8330c5a2cad87acccb015 to your computer and use it in GitHub Desktop.
Wait -- an ES6 promise example
const wait = time => new Promise((resolve) => setTimeout(resolve, time));
wait(3000).then(() => console.log('Hello!')); // 'Hello!'
@lubegasimon
Copy link

Hi, could you please help explain "const wait '= time =>' new Promise" especially the statements enclosed in single quote and how they related to the whole line of code ..

Thanks..

@vixeven
Copy link

vixeven commented Aug 11, 2018

const wait = function(time) {
    return new Promise(function(resolve) {
	setTimeout(resolve, time)
    })
}

wait(3000)
.then(function() {
	console.log('Hello!');
});

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