0

Im learning bacon.js i wrote test script like that.

var bacon = require('../nodejs/node_modules/baconjs').Bacon;
function TestClass(URL,port,username,password)
{  
  this.funcCheck = function( data , rescallback)
  {
    console.log(" data: " + data);
    if(data.length > 4)
    {
      rescallback(null,data.substring(0, 2));
    }
    else
    {
      console.log("Calling callback with error data: " + "error");
      rescallback("Too short",null);
    }
  }
}   
var tclass = new TestClass();
var names = ['Geroge','Valentine', 'Oz','Nickolas'];
var results = [];
var read  = bacon.fromNodeCallback( tclass.funcCheck, bacon.fromArray(names) )   
stream.onValue(function(value) 
{
  console.log(" onValue " + value);
  results.push( value);  
});

stream.onError( function(error)
{
  console.log(" OnError " + error);
 // results.push( err);
});
console.log(" results " + results);

The problem is that onError never get called, despite the fact that "Oz" is less than 4 characters and i know that rescallback get called with 1 parameter that is not null. I can see log printout. The other thing is that if i change defition of onError and put it before onValue, onError will be called exactly 1 time, and onValue will never be called. Im sure im missing something very basic but i dont know what exactly. What im doing wrong? Thanks

AlexS
  • 927
  • 4
  • 16
  • 29
  • I don't understand why you'd use bacon.fromArray(names) instead of just names. Also, you probably mean "read.onValue" instead of "stream.onValue". Anyway I created a fiddle with that correction and it seems to work just fine: http://jsfiddle.net/rq4ND/1/ – raimohanska Jul 21 '14 at 17:50
  • In your example, the fromArray call seems pointless, but if you seriously are going to use fromArray, have a look at this: https://github.com/baconjs/bacon.js/wiki/FAQ#why-isnt-my-subscriber-called – raimohanska Jul 21 '14 at 17:51

0 Answers0