Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="log"><pre></pre></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Just to make it a bit easier on CodePen
const log = s => { document.querySelector('#log pre').innerHTML += s + '\n'  };
const delay = x => { 
	return new Promise(resolve => setTimeout(resolve, x*1000));
}

const makePromise = (name, secs, fail=false) => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			if(!fail) { log(`Good result for ${name}`); resolve(`Resolve from ${name}`); }
			else { log(`Bad result for ${name}`); reject(`Fail from ${name}`); }
		}, secs * 100);
	});
}

(async () => {

	log('TEST ONE - Promise.all(all good)');
	let test = [
		makePromise('alpha', 3),
		makePromise('bob', 1),
		makePromise('charly', 3)
	];

	results = await Promise.all(test);	
	log('Results from test with Promise.all');
	log(JSON.stringify(results));

	log('\n\nTEST TWO  - Promise.all (one bad)');	
	test = [
		makePromise('alpha', 3),
		makePromise('failwhale', 1, true),
		makePromise('charly', 3)
	];

	try {
		let results = await Promise.all(test);
	} catch(e) {
		log(`Expected failure in test: ${e}`);
	}

	// Wait for previous stuff to wrap up
	await delay(3);

	//Alternate
	log('\n\nTEST TWO A - Promise.all (one bad), modified handler.');	
	Promise.all(test).then(results => log('all good')).catch(e => log('one bad'));
	
	// Wait for previous stuff to wrap up
	await delay(3);
	
	log('\n\nTEST THREE - Promise.allSettled (all good)');
	test = [
		makePromise('alpha', 3),
		makePromise('bob', 1),
		makePromise('charly', 3)
	];

	results = await Promise.allSettled(test);	
	log('Results from test with Promise.allSettled');
	log(JSON.stringify(results,null,'\t'));

	log('\n\nTEST FOUR - Promise.allSettled (one bad)');
	test = [
		makePromise('alpha', 3),
		makePromise('failwhale', 1, true),
		makePromise('charly', 3)
	];

	results = await Promise.allSettled(test);	
	log('Results from test with Promise.allSettled');
	log(JSON.stringify(results,null,'\t'));

	log('\n\nTEST FIVE - Promise.any(all good)');
	test = [
		makePromise('alpha', 3),
		makePromise('bob', 1),
		makePromise('charly', 3)
	];

	results = await Promise.any(test);	
	log('Results from test with Promise.any');
	log(results);
	
	await delay(3);

	log('\n\nTEST SIX - Promise.any(one bad)');
	test = [
		makePromise('alpha', 3),
		makePromise('bad bob', 1, true),
		makePromise('charly', 3)
	];

	results = await Promise.any(test);	
	log('Results from test with Promise.any');
	log(results);

	await delay(3);

	log('\n\nTEST SEVEN - Promise.any(all bad)');
	test = [
		makePromise('alpha', 3, true),
		makePromise('bad bob', 1, true),
		makePromise('charly', 3, true)
	];
	
	try {
		let results = await Promise.any(test);
		log(results);
	} catch(e) {
		log(`Expected failure in test: ${e}`);
		log(e.errors);
	}
	
	
	log('\n\nTEST RAY EIGHT - Promise.race(all good)');
	test = [
		makePromise('alpha', 3),
		makePromise('bob', 1),
		makePromise('charly', 3)
	];
	results = await Promise.race(test);	
	log('Results from test with Promise.race');
	log(results);

	await delay(3);

	log('\n\nTEST NINE - Promise.race(bad guy wins)');
	test = [
		makePromise('alpha', 3),
		makePromise('worst bob', 1, true),
		makePromise('charly', 3)
	];
	try {
		let results = await Promise.race(test);
	} catch(e) {
		log(`Expected failure in test: ${e}`);
	}

})();


              
            
!
999px

Console