Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function runCancelEffect(env, taskOrTasks, cb, { task }) {
if (taskOrTasks === SELF_CANCELLATION) {
cancelSingleTask(task)
} else if (is.array(taskOrTasks)) {
taskOrTasks.forEach(cancelSingleTask)
} else {
cancelSingleTask(taskOrTasks)
}
cb()
// cancel effects are non cancellables
}
export default function matcher(pattern) {
// prettier-ignore
const matcherCreator = (
pattern === '*' ? wildcard
: is.string(pattern) ? string
: is.array(pattern) ? array
: is.stringableFunc(pattern) ? string
: is.func(pattern) ? predicate
: is.symbol(pattern) ? symbol
: null
)
if (matcherCreator === null) {
throw new Error(`invalid pattern: ${pattern}`)
}
return matcherCreator(pattern)
}
function getFnCallDescriptor(fnDescriptor, args) {
let context = null
let fn
if (is.func(fnDescriptor)) {
fn = fnDescriptor
} else {
if (is.array(fnDescriptor)) {
;[context, fn] = fnDescriptor
} else {
;({ context, fn } = fnDescriptor)
}
if (context && is.string(fn) && is.func(context[fn])) {
fn = context[fn]
}
}
return { context, fn, args }
}
addDescResult(descriptor, ignoreResult) {
const { status, result, error, duration } = descriptor
if (status === RESOLVED && !ignoreResult) {
if (is.array(result)) {
this.addValue(' 🡲 ')
this.addValue(result)
} else {
this.appendData('🡲', result)
}
} else if (status === REJECTED) {
this.appendData('🡲 ⚠', error)
} else if (status === PENDING) {
this.appendData('⌛')
} else if (status === CANCELLED) {
this.appendData('🡲 Cancelled!')
}
if (status !== PENDING) {
this.appendData(`(${duration.toFixed(2)}ms)`)
}
function runAllEffect(env, effects, cb, { digestEffect }) {
const effectId = currentEffectId
const keys = Object.keys(effects)
if (keys.length === 0) {
cb(is.array(effects) ? [] : {})
return
}
const childCallbacks = createAllStyleChildCallbacks(effects, cb)
keys.forEach(key => {
digestEffect(effects[key], effectId, childCallbacks[key], key)
})
}
export function join(taskOrTasks) {
if (process.env.NODE_ENV !== 'production') {
if (arguments.length > 1) {
throw new Error('join(...tasks) is not supported any more. Please use join([...tasks]) to join multiple tasks.')
}
if (is.array(taskOrTasks)) {
taskOrTasks.forEach(t => {
check(t, is.task, `join([...tasks]): argument ${t} is not a valid Task object ${TEST_HINT}`)
})
} else {
check(taskOrTasks, is.task, `join(task): argument ${taskOrTasks} is not a valid Task object ${TEST_HINT}`)
}
}
return makeEffect(effectTypes.JOIN, taskOrTasks)
}
if (taskToJoin.isRunning()) {
const joiner = { task, cb }
cb.cancel = () => {
if (taskToJoin.isRunning()) remove(taskToJoin.joiners, joiner)
}
taskToJoin.joiners.push(joiner)
} else {
if (taskToJoin.isAborted()) {
cb(taskToJoin.error(), true)
} else {
cb(taskToJoin.result())
}
}
}
if (is.array(taskOrTasks)) {
if (taskOrTasks.length === 0) {
cb([])
return
}
const childCallbacks = createAllStyleChildCallbacks(taskOrTasks, cb)
taskOrTasks.forEach((t, i) => {
joinSingleTask(t, childCallbacks[i])
})
} else {
joinSingleTask(taskOrTasks, cb)
}
}