Coordinate scoped model reads with bounded streaming state and identity fences
This commit is contained in:
@@ -8,9 +8,22 @@ import { stripTypeScriptTypes } from 'node:module';
|
||||
import { setTimeout as pause } from 'node:timers/promises';
|
||||
|
||||
const root = resolve(import.meta.dirname, '../..'), profile = await mkdtemp(join(tmpdir(), 'endoleap-storage-browser-'));
|
||||
const readStreams=new Map();
|
||||
const server = createServer(async (request, response) => {
|
||||
try {
|
||||
const path = new URL(request.url, 'http://localhost').pathname;
|
||||
if(path==='/loader-stream'){
|
||||
const url=new URL(request.url,'http://localhost'),key=url.searchParams.get('key');
|
||||
if(!key){response.writeHead(400).end();return;}
|
||||
const state=readStreams.get(key)??{reads:0};state.reads++;state.response=response;readStreams.set(key,state);
|
||||
response.writeHead(200,{'Content-Type':'application/x-ndjson'});response.write(JSON.stringify({part:0,complete:false})+'\n');return;
|
||||
}
|
||||
if(path==='/loader-release'){
|
||||
const url=new URL(request.url,'http://localhost'),state=readStreams.get(url.searchParams.get('key'));
|
||||
if(!state){response.writeHead(404).end();return;}
|
||||
if(!state.response.destroyed)state.response.end(url.searchParams.get('fail')==='1'?'{invalid tail}\n':JSON.stringify({part:1,complete:true})+'\n');
|
||||
response.setHeader('Content-Type','application/json');response.end(JSON.stringify({reads:state.reads}));return;
|
||||
}
|
||||
if (path === '/') { response.setHeader('Content-Type', 'text/html'); response.end('<title>Headless storage checks</title>'); return; }
|
||||
const filename = resolve(root, `.${path}`);
|
||||
if (!filename.startsWith(`${root}/src/lib/`) && !filename.startsWith(`${root}/tests/headless/`)) { response.writeHead(404).end(); return; }
|
||||
|
||||
Reference in New Issue
Block a user