MCPcopy
hub / github.com/QwikDev/qwik / runTask

Function runTask

packages/qwik/src/core/use/use-task.ts:672–729  ·  view source on GitHub ↗
(
  task: TaskDescriptor | ComputedDescriptor<unknown>,
  containerState: ContainerState,
  rCtx: RenderContext
)

Source from the content-addressed store, hash-verified

670};
671
672export const runTask = (
673 task: TaskDescriptor | ComputedDescriptor<unknown>,
674 containerState: ContainerState,
675 rCtx: RenderContext
676): ValueOrPromise<void> => {
677 task.$flags$ &= ~TaskFlagsIsDirty;
678
679 cleanupTask(task);
680 const hostElement = task.$el$;
681 const iCtx = newInvokeContext(rCtx.$static$.$locale$, hostElement, undefined, TaskEvent);
682 iCtx.$renderCtx$ = rCtx;
683 const { $subsManager$: subsManager } = containerState;
684 const taskFn = task.$qrl$.getFn(iCtx, () => {
685 subsManager.$clearSub$(task);
686 }) as TaskFn;
687 const track: Tracker = (obj: (() => unknown) | object | Signal, prop?: string) => {
688 if (isFunction(obj)) {
689 const ctx = newInvokeContext();
690 ctx.$subscriber$ = [0, task];
691 return invoke(ctx, obj);
692 }
693 const manager = getSubscriptionManager(obj);
694 if (manager) {
695 manager.$addSub$([0, task], prop);
696 } else {
697 logErrorAndStop(codeToText(QError_trackUseStore), obj);
698 }
699 if (prop) {
700 return (obj as Record<string, unknown>)[prop];
701 } else if (isSignal(obj)) {
702 return obj.value;
703 } else {
704 return obj;
705 }
706 };
707 const cleanups: (() => void)[] = [];
708 task.$destroy$ = noSerialize(() => {
709 cleanups.forEach((fn) => fn());
710 });
711
712 const opts: TaskCtx = {
713 track,
714 cleanup(callback) {
715 cleanups.push(callback);
716 },
717 };
718 return safeCall(
719 () => taskFn(opts),
720 (returnValue) => {
721 if (isFunction(returnValue)) {
722 cleanups.push(returnValue);
723 }
724 },
725 (reason) => {
726 handleError(reason, hostElement, rCtx);
727 }
728 );
729};

Callers 2

useTaskQrlFunction · 0.85
runSubscriberFunction · 0.85

Calls 7

newInvokeContextFunction · 0.90
noSerializeFunction · 0.90
safeCallFunction · 0.90
isFunctionFunction · 0.90
handleErrorFunction · 0.90
cleanupTaskFunction · 0.85
fnFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…