Scarlett
Scarlett6mo ago

Typing for Dynamic imports

So I have a function like this that uses a dynamic import like
export async function func1(image: uInt8Array[]) {
const {decode, }= await import(
"https://deno.land/x/imagescript@1.2.17/mod.ts"
);
}
export async function func1(image: uInt8Array[]) {
const {decode, }= await import(
"https://deno.land/x/imagescript@1.2.17/mod.ts"
);
}
But this function gets called like once a day, but it gets repeated called like 4 or 5 times at once. So I am just wondering if deno will import that module again and again for each time the function is called? I also tried something like this which breaks typing all together
let import = false
let decode;
export async function func1(image: uInt8Array[]) {
if(!imported){
const {decode:d }= await import("https://deno.land/x/imagescript@1.2.17/mod.ts");
decode = d
imported = true
}
// rest of the function
}
let import = false
let decode;
export async function func1(image: uInt8Array[]) {
if(!imported){
const {decode:d }= await import("https://deno.land/x/imagescript@1.2.17/mod.ts");
decode = d
imported = true
}
// rest of the function
}
2 Replies
AapoAlas
AapoAlas6mo ago
No: Modules are singletons, subsequent imports get the same instance as the first one.
Scarlett
Scarlett6mo ago
Thoughts So :deno_thankyou: