D
Deno

help

Typing for Dynamic imports

SScarlett2/12/2024
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
}
AAapoAlas2/12/2024
No: Modules are singletons, subsequent imports get the same instance as the first one.
SScarlett2/12/2024
Thoughts So :deno_thankyou:

Looking for more? Join the community!