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

Public abort method #15

Open
betonetotbo opened this issue Aug 9, 2017 · 0 comments
Open

Public abort method #15

betonetotbo opened this issue Aug 9, 2017 · 0 comments

Comments

@betonetotbo
Copy link

I just added the abort method on the returned object of oboeWrapper.
This is useful to abort the streaming.

function oboeWrapper(params) {
    var stream = oboe(params);
    var singleArgMethods = ['start', 'done', 'fail'];
    var on = function (event, pattern, callback) {
        var wrappedCallback = function () {
            var args = arguments;

            return $rootScope.$evalAsync(function () {
                return callback.apply(stream, args);
            });
        };

        return singleArgMethods.indexOf(event) >= 0 ? stream.on(event, wrappedCallback)
            : stream.on(event, pattern, wrappedCallback);
    };

    return {
        start: function (callback) {
            return on('start', null, callback);
        },
        node: function (pattern, callback) {
            return on('node', pattern, callback);
        },
        path: function (pattern, callback) {
            return on('path', pattern, callback);
        },
        success: function (callback) {
            return on('done', null, callback);
        },
        done: function (callback) {
            return on('done', null, callback);
        },
        error: function (callback) {
            return on('fail', null, callback);
        },
        fail: function (callback) {
            return on('fail', null, callback);
        },
        abort: function() {
            stream.abort();
        }
    };
}

To use it:

angular.module('app', ['ng-oboe']).controller('controller', function($scope) {
    $scope.stream;
    $scope.init = () => $scope.stream = oboe.get('/my-stream').node('!.*', (node) => console.log(node));
    $scope.close = () => $scope.stream.abort();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant