ethanent/protocore

StreamingAbstractor: Add response ability?

Closed this issue · 1 comments

This would be a really interesting feature to see, but would be somewhat complex to implement efficiently.

It'd work like this.

Schema definition:

myAbstractor.register('login', new Schema([
    {
        'name': 'username',
        'type': 'string'
    },
    {
        'name': 'password',
        'type': 'string'
    }
], new Schema([ // This is the response schema
    {
        'name': 'success',
        'type': 'boolean'
    },
    {
        'name': 'message',
        'type': 'string'
    }
]))

Server:

myAbstractor.on('login', (data, respond) => {
    if (data.username === 'ethanent' && data.password === 'hi') {
        respond({
            'success': true,
            'message': 'Welcome back!'
        })
    }
    else respond({
        'success': false,
        'message': 'Your credentials were incorrect.'
    })
})

Client:

// in an async context...

const loginRes = await myAbstractor.send('login', {
    'username': 'ethanent',
    'password': 'hi'
})

console.log(loginRes)
// => {'success': true, 'message': 'Welcome back!'}

I think that this could be an extremely useful feature, as it would allow applications to have a sense of synchronicity and order.

^^^^^^^^^^^^^^^^

Will be resolved with release 4.0.0!