@multipart/form-data
Version:
Multipart/Form-Data And File Upload Middleware For Koa Written In ES6 And Optimised With JavaScript Compiler.
28 lines (26 loc) • 499 B
JavaScript
import { EventEmitter } from 'events'
export default class Counter extends EventEmitter {
constructor() {
super()
this.value = 0
}
increment () {
this.value++
}
decrement () {
if (--this.value === 0) this.emit('zero')
}
isZero () {
return (this.value === 0)
}
onceZero(fn) {
if (this.isZero()) return fn()
this.once('zero', fn)
}
async awaitZero() {
await new Promise((r, j) => {
this.onceZero(r)
this.once('error', j)
})
}
}