MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / readLoop

Function readLoop

templates/bun-ts/src/main.ts:111–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

109 process.on('SIGTERM', shutdown);
110
111 const readLoop = async () => {
112 while (true) {
113 const { done, value } = await reader.read();
114 if (done) {
115 shutdown();
116 break;
117 }
118
119 const text = decoder.decode(value).trim();
120 if (!text) {
121 prompt();
122 continue;
123 }
124
125 if (text.toLowerCase() === 'list') {
126 console.log('\nPeople in database:');
127 let count = 0;
128 for (const person of conn.db.person.iter()) {
129 console.log(` - ${person.name}`);
130 count++;
131 }
132 if (count === 0) {
133 console.log(' (none)');
134 }
135 console.log();
136 } else if (text.toLowerCase() === 'hello') {
137 conn.reducers.sayHello({});
138 console.log('Called sayHello reducer (check server logs)\n');
139 } else {
140 conn.reducers.add({ name: text });
141 }
142 prompt();
143 }
144 };
145
146 readLoop().catch(err => {
147 console.error('CLI error:', err);

Callers 1

setupCLIFunction · 0.85

Calls 7

logMethod · 0.80
shutdownFunction · 0.70
promptFunction · 0.70
iterMethod · 0.65
readMethod · 0.45
decodeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…