readFile(file, function(data) {
decodeImage(data, function(img) {
resizeImage(img, maxWidth, function(resized) {
applyFilter(resized, 'grayscale', function(filtered) {
exportImage(filtered, 'output.png', function(result) {
console.log("Done!", result);
});
});
});
});
});
function readFilePromise(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = () =>
reject(new Error('Failed to read file'));
reader.readAsDataURL(file);
});
}
readFilePromise(file)
.then(data => decodeImage(data))
.then(img => resizeImage(img, maxWidth))
.then(resized => applyFilter(resized, 'grayscale'))
.then(filtered => exportImage(filtered, 'output.png'))
.then(result => console.log("Done!", result))
.catch(error => showToast(error.message, 'error'));
Flat, readable, one .catch() handles errors from any step. Compare this to the 5-level nested version above.
async function processImage(file) {
try {
const data = await readFilePromise(file);
const img = await decodeImage(data);
const resized = await resizeImage(img, maxWidth);
const filtered = await applyFilter(resized, 'grayscale');
const result = await exportImage(filtered, 'output.png');
console.log("Done!", result);
} catch (error) {
showToast(error.message, 'error');
}
}
const results = await Promise.all([
processImage(file1),
processImage(file2),
processImage(file3),
]);
All 3 images process simultaneously. If sequential processing takes 3 seconds, parallel takes ~1 second. Massive performance win for batch operations.
git switch -c refactor/PIXELCRAFT-018-async-await
git add src/scripts/
git commit -m "Refactor callback hell to async/await (PIXELCRAFT-018)"
git push origin refactor/PIXELCRAFT-018-async-await
# PR → Review → Merge → Close ticket ✅
Promises/Futures exist in almost every modern language.
The concept is universal: represent a value that doesn't exist yet.
You've completed 18 tickets covering:
HTML: document structure, semantic elements, meta tags, forms, accessibility
CSS: selectors, box model, flexbox, grid, animations, responsive design, variables, specificity
JavaScript: variables, conditionals, loops, functions, objects, arrays, DOM, events, Canvas, error handling, strings, localStorage, higher-order functions, event loop, Promises, async/await
Workflow: terminal, Git (branch/commit/push/PR/merge), ticket lifecycle, code review
You navigate the terminal, use Git professionally, follow the ticket workflow, and write clean, non-duplicated code.
🟣 PROMOTION TO JUNIOR DEVELOPER!