webstrand
webstrand
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
I see what you mean about latest, I'm not sure that's fixable given the api createResource offers
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
I'm pretty sure this is safe
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
it discards them,
createComputed(() => console.log("saw handle", handle1.state === "ready" && handle1()))
createComputed(() => console.log("saw handle", handle1.state === "ready" && handle1()))
doesn't report observing any intermediate values produced by fetches that were refetched while running
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
I assumed it discarded it, because I can't imagine otherwise
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
that's true, I need to check that createResource discards the result of the promise, if it's already refetching
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
found a better solution (aside from the refetch bug)
const [handle1, ctrl1] = createResource(ref, async (arg) => {
const task = allocate(arg);
onCleanup(() => task.then(value => console.log("cleanup", value)));
return await task;
});
const [handle1, ctrl1] = createResource(ref, async (arg) => {
const task = allocate(arg);
onCleanup(() => task.then(value => console.log("cleanup", value)));
return await task;
});
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
ah that's helpful, thanks
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
odd that the dev-mode warnings aren't enabled in the playground
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
oof, actually, on refetch getOwner() returns null, so no solution involving onCleanup in the body of the resource fetcher is legal
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
or it'll block loading of the whole component
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
I think that does bad things to suspense, right? need to check the status first
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
yeah. I haven't actually seen that behavior in the wild, but it's probably only a matter of time
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
that onCleanup never runs, since its outside of Owner = context
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
the await allows other code to run, before the promise resolves. The resource could be re-fetched or disposed of in that inbetween space, causing the onCleanup to run before resource gets assigned
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
That's an option, it's just not scheduling the dispose after resource is no longer accessible
const [handle1] = createResource(arg1, async (arg) => {
let isDead = false;
var handle: number | undefined;
onCleanup(() => {
if(handle !== undefined) dispose(handle)
isDead = true;
});
handle = await allocate(arg);
if(isDead) dispose(handle);
return handle;
});
const [handle1] = createResource(arg1, async (arg) => {
let isDead = false;
var handle: number | undefined;
onCleanup(() => {
if(handle !== undefined) dispose(handle)
isDead = true;
});
handle = await allocate(arg);
if(isDead) dispose(handle);
return handle;
});
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
yeah. But what is the alternative to onCleanup? I do realize that if the refetch happens inbetween registering the onCleanup and the await resolving, then the resource gets lost
70 replies
SSolidJS
Created by webstrand on 2/16/2025 in #support
How to onCleanup an async resource from createResource?
using setTimeout doesn't work because the resource will likely be used after an arbitrary period of time, the only time that I can cleanup the resource is when its owner gets disposed, or the value gets refetched
70 replies