
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
when-connected
Advanced tools
call an async method with configurable timeout and when connected if reconnect is used
perform a callback when "connected" or fire callback with timeout error if its taken too long.
the most important thing this does is provides you with the errors required to manage callback and stream disconnection in necessary ways.
this lib is generic and ensures that wrapped calls are only made when connected. these examples use multilevel a package used to interact with leveldb over the network but it is not the only reason this is useful.
var mulitlevel = require('multilevel');
var reconnect = require('reconnect');
var whenConnected = require('when-connected')
var client;
var recon = reconnect(function(stream){
client = multilevel.client();
stream.pipe(client).pipe(stream);
}).connect(PORT);
var get = whenConnected(function(key,cb){
client.get(key,cb);
},{reconnect:recon});
var dumpDB = whenConnected(function(){
return client.createReadStream();
},{reconnect:recon,stream:true});
// get a key.
get('a',function(err,data){
console.log('get called back');
});
var dump = dumpDB();
// output a db dump.
dump.on('data',function(data){
console.log('db: ',data);
});
this exports one function.
whenConnected([the function to call when connected],[options])
error objects returned by this lib all have a code proerty that is one of these values. they are either emitted as errors onn streams or passed as the error to a callback.
FAQs
call an async method with configurable timeout and when connected if reconnect is used
We found that when-connected demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.