I am relatively new to Node, and one thing that concerns me is how I design classes that need to maintain a state where I cannot be sure that they will not be called again before they finish processing the first call.
eg.
var thing = new Thing();
thing.doSomething(function() { alert('done') });
thing.doSomething(function() { alert('done') });
thing.doSomething(function() { alert('done') });
thing.doSomethingStateful(function() { alert('done') });
thing.doSomethingStateful(function() { alert('done') });
Is there a design template that helps solve this problem? Should I always strive to make Node classes standstill and use an internal state object to track the state of each call? Or is there a convention to differentiate classes that can be used asynchronously and those that support state?
source
share