A
Size: a a a
A
A
A
SB
SB

new Promise с обработкой его catch, хотелось бы без таких костылей. Есть идеи?)return new Error(...) ?СК
return new Error(...) ?YK

new Promise с обработкой его catch, хотелось бы без таких костылей. Есть идеи?)СК

СК
СК
SB
createError()СК
createError()const SOME_ERROR = createError('SOME_ERROR')SB
SB
СК
SB
throw SOME_ERROR ?СК
throw SOME_ERROR ?function stoppable (target, key, descriptor) {
const STOP_ERROR = createError('STOP_ERROR')
let queue = Promise.resolve()
let lockedQueue = Promise.resolve()
const decoratedDescriptor = Object.assign({}, descriptor, {
value: function (...args) {
return queue = queue
.then(() => descriptor.value.apply(this, args))
.catch((reason) => {
if (reason !== STOP_ERROR) {
console.log('Skip error in @stopabble', reason)
throw reason
} else {
console.log('Catch error in @stoppable', reason)
}
})
},
})
Object.defineProperties(decoratedDescriptor.value, {
start: {
proto: null,
value: () => {
queue = lockedQueue
},
},
stop: {
proto: null,
value: () => {
lockedQueue = queue
queue = Promise.reject(STOP_ERROR)
},
},
})
return decoratedDescriptor
}СК
function stoppable (target, key, descriptor) {
const STOP_ERROR = createError('STOP_ERROR')
let queue = Promise.resolve()
let lockedQueue = Promise.resolve()
const decoratedDescriptor = Object.assign({}, descriptor, {
value: function (...args) {
return queue = queue
.then(() => descriptor.value.apply(this, args))
.catch((reason) => {
if (reason !== STOP_ERROR) {
console.log('Skip error in @stopabble', reason)
throw reason
} else {
console.log('Catch error in @stoppable', reason)
}
})
},
})
Object.defineProperties(decoratedDescriptor.value, {
start: {
proto: null,
value: () => {
queue = lockedQueue
},
},
stop: {
proto: null,
value: () => {
lockedQueue = queue
queue = Promise.reject(STOP_ERROR)
},
},
})
return decoratedDescriptor
}YK
СК