Skip to content

assert.async #22

Description

@DonutEspresso

For modules that expose async public APIs, I often want to assert but want the assertion error returned via the callback. I do this frequently to avoid reimplementing non-throwing validation at the caller (i.e., a server handler), and to avoid usage of try/catch at the caller. I'm thinking a wrapper that takes a function of assertions and a callback:

assert.async(function() {
  assert.object(opts, 'opts');
  assert.number(opts.ttl, 'opts.ttl');
}, callback);

I realize this somewhat conflicts with the spirit and ethos of assertions. It's easy enough to wrap in userland, but figured it wouldn't hurt to ask if this seemed like something useful. Would be happy to file a PR if so - otherwise, feel free to close.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions