Skip to content

[🐞] v2 solve problem with async computed used in tasks #7683

@Varixo

Description

@Varixo

Problem:
https://qwikdev-build-v2.qwik-8nx.pages.dev/playground/#f=Q0o0xoYG2BKNDij1OYIyMDwZg4XA5RuF7RRI4JQAS2Zg4GBYA1UILcj1oAWhhqGBJtDtQN3wyhthIMRIWKWvnpiUnKIOVAySANmiB8y0pakgfq0myAQqtJNwJ3xDS6SmHSkJHyUoR5M9LZI9AA

  const test = useAsyncComputed$(() => Promise.resolve(10));
  useTask$(() => {
    console.log('abcd');
    test.value;
  })

The "abcd" will be logged twice, because test.value throws a promise to resolve it sync.
Possible solutions:

  • expose the retryOnPromise function, user needs to wrap any .value call of async computed like await retryOnPromise(() => test.value);
  • new method on async computed called resolve, under the hood it will call compute wrapped in retryOnPromise. It returns promise. User needs to await for it.
  • before running a task check the scope vars deeply to see if there are async computed signals (can slowdown a qrl execution)

in first two cases also eslint rule is needed and warn user about consequences not using retryOnPromise or resolve

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Upcoming

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions