Building an AI-Powered IDE Companion App
mesmacosta.medium.com1 pointsby graup2 comments
{'name__contains':"k", "age__lt":20}
Kind of tangential to this package, but I've always loved this filter query syntax. Does it have a name? import {recv, Chan, Select} from 'ts-chan';
const ch1 = new Chan<number>();
const ch2 = new Chan<string>();
void sendsToCh1ThenEventuallyClosesIt();
void sendsToCh2();
const select = new Select([recv(ch1), recv(ch2)]);
for (let running = true; running;) {
const i = await select.wait();
switch (i) {
case 0: {
const v = select.recv(select.cases[i]);
if (v.done) {
running = false;
break;
}
console.log(`rounded value: ${Math.round(v.value)}`);
break;
}
case 1: {
const v = select.recv(select.cases[i]);
if (v.done) {
throw new Error('ch2 unexpectedly closed');
}
console.log(`uppercase string value: ${v.value.toUpperCase()}`);
break;
}
default:
throw new Error('unreachable');
}
}
I would consider rewriting the API to something like this: import { receive, Channel, select } from 'ts-chan';
const ch1 = new Channel<number>();
const ch2 = new Channel<string>();
void sendsToCh1ThenEventuallyClosesIt();
void sendsToCh2();
for (let running = true; running;) {
switch(await select([receive(ch1), receive(ch2)])) {
case ch1: {
if (ch1.done) {
running = false;
break;
}
console.log(`rounded value: ${Math.round(ch1.value)}`);
}
case ch2: {
if (ch1.done) {
throw new Error('ch2 unexpectedly closed');
}
console.log(`uppercase string value: ${ch2.value.toUpperCase()}`);
break;
}
}
}