Search code examples
ibm-cloudopenwhisk

Anyway to stop a sequence of actions?


I sort of like the idea of sequences, but I would like to be able to have an action basically stop the sequence. The idea is to have an action which filters the incoming message, and if it doesn't meet certain criteria it would return false or something and essentially stop the processing of the sequence.

I could probably incorporate a convention myself, but wondered if there was a mechanism.


Solution

  • You can fail the filtering action by returning a rejected Promise instead of a resolved one. That will fail the action and thus break the sequence at that point.

    Here's a short example that might help:

    function main(args) {
        if(args.myValue == "myValue") {
            return Promise.resolve({...});
        } else
            return Promise.reject({...});
        }
    }