> If you could give me a bit more detailed solution on using fibers, I 
would be really happy.
Don't know if this helps, it's a sample of how to use fibers to make API of 
MongoDB driver looks like synchronous.
http://alexeypetrushin.github.com/mongo-model/synchronous.html

On Tuesday, March 20, 2012 7:34:10 PM UTC+4, Bika wrote:
>
> Yeah, these are those 3 solutions that I wanted to avoid. :)
>
> Actually, wrt your first option. I can not go with fibers as I plan to use 
> nodejitsu first, and you can't install compiled code. But even if I could, 
> I could not figure out how to do it with a fibers alternative that we use, 
> async.
>
> If you could give me a bit more detailed solution on using fibers, I would 
> be really happy.
>
> thx
>
> 2012. március 20., kedd 16:19:14 UTC+1 időpontban Alexey Petrushin a 
> következőt írta:
>>
>> I believe there may be 3 possible solutions:
>>
>> - You may try to use fibers to make Your async code looks like a sync. I 
>> gues it may work, but I'm not sure about it.
>> - Hack Backbone Model, it's sources are small and clear and it shouldn't 
>> be too complex.
>> - Create Your own async model. You can use any model implementation with 
>> Backbone.js, it's very modular and works well with custom stuff. 
>> For example, here's my own custom model I use with Backbone for my 
>> project (I did it because I don't like to write user.get('name') and prefer 
>> user.name and also for some other reasons)
>>
>> https://github.com/alexeypetrushin/rad_core/blob/master/assets/rad/models.coffee
>>
>> https://github.com/alexeypetrushin/rad_core/blob/master/assets/rad_spec/model_spec.coffee
>>
>>
>> On Tuesday, March 20, 2012 3:12:57 PM UTC+4, Bika wrote:
>>>
>>> hi,
>>>
>>> I'm trying to use backbone for "everything" on the server side too, and 
>>> got stuck with doing a proper validation. The problem is that backbone's 
>>> validate method return a boolean, and the validation mechanics should be 
>>> implemented inside of it, but with node these mechanics are asynchronous, 
>>> thus the validate method returns before evaluating my code.
>>>
>>> Here is a code sample that illustrates well my setup:
>>>
>>> Backbone.Model.extend({
>>>   validate: function(){
>>>     var result;
>>>     Jobs._withCollection(function(err, collection){
>>>       collection.count(query, function(count){
>>>          result = count > 1 ? "Job already exist" : null;
>>>       });
>>>     })
>>>     return result;
>>>   }
>>> })
>>>
>>> I might be able to improve this a little bit, but I'm not sure if this 
>>> would work:
>>>
>>> function _validate(){
>>>     Jobs._withCollection(function(err, collection){
>>>       collection.count(query, function(count){
>>>          yield count > 1 ? "Job already exist" : null;
>>>       });
>>>     })
>>> }
>>>
>>> Backbone.Model.extend({
>>>   validate: function(){
>>>     return _validate.call(this);
>>>   }
>>> })
>>>
>>> Especially not for a bit more complex situations where I use async for 
>>> example, and the return value is set in the last callback of async, like 
>>> here (this is obviously wrong as res is null at return):
>>>
>>> Backbone.Model.extend({
>>>   validate: function(){
>>>     var res;
>>>     async.parallel([
>>>         .. do stuff ..
>>>     ], function(err, results){
>>>         res = results;
>>>     })
>>>     return results;
>>>   }
>>> })
>>>
>>> Any ideas?
>>>
>>> Viktor
>>> close
>>>
>>>    
>>> close
>
>    
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to