프로미스
Promise
Callback style code
import fs = require('fs')
function loadJSONSync(filename: string) {
return JSON.parse(fs.readFileSync(filename))
}
// good json file
console.log(loadJSONSync('good.json'))
// non-existent file, so fs.readFileSync fails
try {
console.log(loadJSONSync('absent.json'))
} catch (err) {
console.log('absent.json error', err.message)
}
// invalid json file i.e. the file exists but contains invalid JSON so JSON.parse fails
try {
console.log(loadJSONSync('invalid.json'))
} catch (err) {
console.log('invalid.json error', err.message)
}Creating a Promise

Subscribing to the fate of the promise
Chain-ability of Promises
TypeScript and promises
Converting a callback style function to return a promise
Revisiting the JSON example
Parallel control flow
Last updated