You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{createServer,Socket}from'net';constFEED_SOCKETS_BASE_PATH='/tmp/';constunlinkFeeds: Array<string>=[];constcreateFeedPublisher=async(feedName: string)=>{constsockName=FEED_SOCKETS_BASE_PATH+feedName;unlinkFeeds.push(sockName);constlisteners: {[key: number]: Socket}=[];constserver=createServer((socket)=>{constuid=Object.keys(listeners).length;listeners[uid]=socket;console.log(`A listener ${uid} connected to feed ${feedName}. Num listeners ${Object.keys(listeners).length}`);socket.on('end',()=>{deletelisteners[uid];console.log(`Listener ${uid} disconnected from feed ${feedName}. Num listeners ${Object.keys(listeners).length}`);});socket.on('error',(err)=>{deletelisteners[uid];console.error(`Listener ${uid} error on feed ${feedName}, deleted listener. Num listeners ${Object.keys(listeners).length}`,err);});});server.listen(sockName,()=>{console.log(`Feed ${feedName} server running on ${sockName}`);});return(data: object)=>{conststr=JSON.stringify(data);for(constsockofObject.values(listeners)){sock.write(str+'\n');}};};constpublishFeed=awaitcreateFeedPublisher('testFeed');setInterval(()=>{publishFeed(undefinedasany)},1000);
In listener.ts
constFEED_SOCKETS_BASE_PATH='/tmp/';import{createConnection}from'net';constsubscribeFeed=async(feedName: string,dataCallback: (json: object)=>void)=>{constsockPath=FEED_SOCKETS_BASE_PATH+feedName;constconnect=()=>{constreconnect=()=>{setTimeout(()=>{console.log(`Reconnecting to feed ${feedName}`);connect();},1000);};letclient=createConnection(sockPath);client.on('connect',()=>{console.log(`Connected to feed ${feedName} socket`);});client.on('data',(dataStr: string)=>dataCallback(JSON.parse(dataStr)));client.on('end',()=>{console.error(`Connection to feed ${feedName} closed, attempting reconnection`);reconnect();});client.on('error',(err)=>{console.error(err)client.destroy()reconnect()});};connect();};subscribeFeed('testFeed',data=>{console.log(data)});
Then bun publisher.ts in one terminal followed by bun listener.ts in another terminal
What is the expected behavior?
The second terminal repeatedly outputs a javascript JSON parse error
What do you see instead?
The second terminal repeatedly outputs a [native code: Exception] error
Additional information
No response
The text was updated successfully, but these errors were encountered:
What version of Bun is running?
1.1.44+ec11ea4e7
What platform is your computer?
Linux 5.15.0-130-generic x86_64 x86_64
What steps can reproduce the bug?
In publisher.ts
In listener.ts
Then
bun publisher.ts
in one terminal followed bybun listener.ts
in another terminalWhat is the expected behavior?
The second terminal repeatedly outputs a javascript JSON parse error
What do you see instead?
The second terminal repeatedly outputs a
[native code: Exception]
errorAdditional information
No response
The text was updated successfully, but these errors were encountered: