Thread safe collection with concurrent requests

74 views
Skip to first unread message

Chathuranga

unread,
Dec 2, 2014, 7:21:26 AM12/2/14
to nod...@googlegroups.com

I am converting .net program in to node js

In .Net I used a blocking collection to keep 3rd party objects and it gives one object per request and waits until it filled.

BlockingCollection<DBAPP> DbDriverPool; //I can keep around 80 objects in that pool. (Due to memory usage)

MyProcess(){

   
Var obj = DbDriverPool.Take();

   
//do taks

   
DbDriverPool.Add(obj)

}


Every request will get separate obj and requests which doesn't have obj will wait until free obj is added to BlockingCollection.

I do not want to keep obj in nodejs like this. I only need a function to return integer between 0-80 for each concurrent request and rest of request should wait until integer is available. 

(I am completely new to node js and also for javascripts) Can someone explain me how to do this?

Ryan Schmidt

unread,
Dec 2, 2014, 10:04:00 PM12/2/14
to nod...@googlegroups.com
There are many npm modules that others have written to solve resource-pool problems. Here's one:

https://www.npmjs.org/package/generic-pool


Reply all
Reply to author
Forward
0 new messages