Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API - allow ways to mute and umute callbacks #1

Closed
jesseskinner opened this issue Feb 7, 2015 · 1 comment
Closed

API - allow ways to mute and umute callbacks #1

jesseskinner opened this issue Feb 7, 2015 · 1 comment
Assignees
Milestone

Comments

@jesseskinner
Copy link
Owner

Perhaps there should be some new API to enable muting and unmuting streams.

We can add these methods as properties of the function that gets returned from solve.

var randomNumberStream = solve(function (callback) {
        setInterval(function () {
            callback(Math.random());
        }, 500);
});

var logRandomNumbers = randomNumberStream(function (number) {
    console.log(number);
});

// stop logging
logRandomNumbers.mute();

// continue logging
logRandomNumbers.unmute();

// stop any listeners on any random number stream
randomNumberStream.mute();
@jesseskinner jesseskinner self-assigned this Feb 7, 2015
@jesseskinner jesseskinner added this to the 1.2.0 milestone Feb 7, 2015
@jesseskinner
Copy link
Owner Author

On second thought, it can be implemented from outside (without adding new API) using this technique. I always prefer to avoid API if possible.

function createMuteSolve(data) {
  var isMuted = false;

  var solver = solve(function (callback) {
    solve(data, function (result) {
      if (isMuted === false) {
        callback(result);
      }
    });
  });

  solver.mute = function() { isMuted = true; };
  solver.unmute = function() { isMuted = false; };

  return solver;
}

var solver = createMuteSolve({ data: getStuff });

// add callback
solver(function(result) { /* do stuff */ });

// mute callback
solver.mute();

// unmute callback
solver.unmute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant