Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
- By cancelling the parent task manually
- By joining a Cancelled task
**/
mainTask.status = CANCELLED
/**
Cancels the current effect; this will propagate the cancellation down to any called tasks
**/
next.cancel()
/**
If this Generator has a `return` method then invokes it
This will jump to the finally block
**/
result = is.func(iterator.return) ? iterator.return(TASK_CANCEL) : { done: true, value: TASK_CANCEL }
} else if (shouldTerminate(arg)) {
// We get TERMINATE flag, i.e. by taking from a channel that ended using `take` (and not `takem` used to trap End of channels)
result = is.func(iterator.return) ? iterator.return() : { done: true }
} else {
result = iterator.next(arg)
}
if (!result.done) {
digestEffect(result.value, parentEffectId, next)
} else {
/**
This Generator has ended, terminate the main task and notify the fork queue
**/
if (mainTask.status !== CANCELLED) {
mainTask.status = DONE
}
mainTask.cont(result.value)
}
} catch (error) {
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 }
}
export function safeName(patternOrChannel) {
if (is.channel(patternOrChannel)) {
return 'channel'
}
if (is.stringableFunc(patternOrChannel)) {
return String(patternOrChannel)
}
if (is.func(patternOrChannel)) {
return patternOrChannel.name
}
return String(patternOrChannel)
}
const validateFnDescriptor = (effectName, fnDescriptor) => {
check(fnDescriptor, is.notUndef, `${effectName}: argument fn is undefined or null`)
if (is.func(fnDescriptor)) {
return
}
let context = null
let fn
if (is.array(fnDescriptor)) {
;[context, fn] = fnDescriptor
check(fn, is.notUndef, `${effectName}: argument of type [context, fn] has undefined or null \`fn\``)
} else if (is.object(fnDescriptor)) {
;({ context, fn } = fnDescriptor)
check(fn, is.notUndef, `${effectName}: argument of type {context, fn} has undefined or null \`fn\``)
} else {
check(fnDescriptor, is.func, `${effectName}: argument fn is not function`)
return
}