Skip to content

Instantly share code, notes, and snippets.

@frxstrem
Forked from andeplane/fetch_async_await.js
Last active January 31, 2018 20:58
Show Gist options
  • Save frxstrem/81b2347a1a731d3798170e59d4b15dd3 to your computer and use it in GitHub Desktop.
Save frxstrem/81b2347a1a731d3798170e59d4b15dd3 to your computer and use it in GitHub Desktop.
import test from './test.txt'
class A {
constructor() { }
async loadFile(filename) {
// let data = await (await fetch(filename))
// return data
return fetch(filename)
}
}
class B extends A {
//constructor() {
// super()
// this.contents = ''
//}
async loadFile(filename) {
//let data = await super.loadFile(filename)
//data.text().then( text => {
// console.log('Text: ', text)
// this.parse(text)
//}).catch( error => {
// console.log('Error: ', error)
//})
try {
return super.loadFile(filename)
} catch (e) {
console.log('Error: ', error)
}
}
//parse (data) {
// this.contents = data
// console.log('Parsing data: ', data)
//}
}
let b = new B()
//b.loadFile(test).then( () => {
// console.log('Got data now: ', b.contents)
//})
b.loadFile(test).then( contents => {
console.log('Got data now: ', contents)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment