raaymax
raaymax
DDeno
Created by raaymax on 9/29/2024 in #help
How to workaround `deno compile` binary file limitations?
In my app I'm using sharp and after compile it looses the ability to load dll.
❯ ./server
error: Uncaught (in promise) Error: Could not load the "sharp" module using the darwin-arm64 runtime
undefined: dlopen(/var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/@img+sharp-darwin-arm64@0.33.0/node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node, 0x0001): tried: '/var/folders/4f/6rr3fjvx2wq742xvnz3lf17)
Possible solutions:
- Add platform-specific dependencies:
npm install --os=darwin --cpu=arm64 sharp
or
npm install --force @img/sharp-darwin-arm64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:85:9)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:88:4)
at Module._compile (node:module:736:34)
at Object.Module._extensions..js (node:module:757:11)
at Module.load (node:module:655:32)
at Function.Module._load (node:module:523:13)
at Module.require (node:module:674:19)
at require (node:module:801:16)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:10:1)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:446:4)
❯ ./server
error: Uncaught (in promise) Error: Could not load the "sharp" module using the darwin-arm64 runtime
undefined: dlopen(/var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/@img+sharp-darwin-arm64@0.33.0/node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node, 0x0001): tried: '/var/folders/4f/6rr3fjvx2wq742xvnz3lf17)
Possible solutions:
- Add platform-specific dependencies:
npm install --os=darwin --cpu=arm64 sharp
or
npm install --force @img/sharp-darwin-arm64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:85:9)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:88:4)
at Module._compile (node:module:736:34)
at Object.Module._extensions..js (node:module:757:11)
at Module.load (node:module:655:32)
at Function.Module._load (node:module:523:13)
at Module.require (node:module:674:19)
at require (node:module:801:16)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:10:1)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:446:4)
Is there any way to workaround this problem?
3 replies
DDeno
Created by raaymax on 7/28/2024 in #help
Event loop resolving prematurely
It looks like event loop clears on await it.return?.(); call which is really strange. I can't figure out whats happening here and where the problem is. Can anyone help with that?
import { assert } from 'jsr:@std/assert@^1.0.0';

async function* abortable(
p: ReadableStream<Uint8Array>,
signal: AbortSignal,
): AsyncGenerator<Uint8Array> {
signal.throwIfAborted();
const { promise, reject } = Promise.withResolvers<never>();
const abort = () => reject(signal.reason);
signal.addEventListener("abort", abort, { once: true });

const it = p[Symbol.asyncIterator]();
try{
while (true) {
const race = Promise.race([promise, it.next()]);
race.catch(() => {
signal.removeEventListener("abort", abort);
});
const { done, value } = await race;
if (done) {
signal.removeEventListener("abort", abort);
return;
}
yield value;
}
}catch(e){
await it.return?.();
throw e;
}
}

Deno.test('aborting streams', async () => {
let streamClosed = false;
const stream = new ReadableStream<Uint8Array>({
cancel() {
streamClosed = true;
console.log('Stream closed');
}
});
console.log('stream created');
const signalController = new AbortController();
setTimeout(() => signalController.abort(), 1000);
try{
for await (const _ of abortable(stream, signalController.signal)) {
console.log('Got data');
}
}catch(e){
console.error(e);
}
console.log('Stream closed');
assert(streamClosed);
});
import { assert } from 'jsr:@std/assert@^1.0.0';

async function* abortable(
p: ReadableStream<Uint8Array>,
signal: AbortSignal,
): AsyncGenerator<Uint8Array> {
signal.throwIfAborted();
const { promise, reject } = Promise.withResolvers<never>();
const abort = () => reject(signal.reason);
signal.addEventListener("abort", abort, { once: true });

const it = p[Symbol.asyncIterator]();
try{
while (true) {
const race = Promise.race([promise, it.next()]);
race.catch(() => {
signal.removeEventListener("abort", abort);
});
const { done, value } = await race;
if (done) {
signal.removeEventListener("abort", abort);
return;
}
yield value;
}
}catch(e){
await it.return?.();
throw e;
}
}

Deno.test('aborting streams', async () => {
let streamClosed = false;
const stream = new ReadableStream<Uint8Array>({
cancel() {
streamClosed = true;
console.log('Stream closed');
}
});
console.log('stream created');
const signalController = new AbortController();
setTimeout(() => signalController.abort(), 1000);
try{
for await (const _ of abortable(stream, signalController.signal)) {
console.log('Got data');
}
}catch(e){
console.error(e);
}
console.log('Stream closed');
assert(streamClosed);
});
Execution result
❯ deno test -A strange.test.ts
running 1 test from ./oko.test.ts
aborting streams ...
------- output -------
stream created
----- output end -----

ok | 0 passed | 0 failed (1s)

error: Promise resolution is still pending but the event loop has already resolved.
❯ deno test -A strange.test.ts
running 1 test from ./oko.test.ts
aborting streams ...
------- output -------
stream created
----- output end -----

ok | 0 passed | 0 failed (1s)

error: Promise resolution is still pending but the event loop has already resolved.
4 replies