var server = new PromiseIO({ someFunc: function(input) { return 'I got: ' + input; } }); server.listen(3000);
someFunc
after connecting to the server: var client = new PromiseIO(); client.connect('http://localhost:3000').then(function(remote) { return remote.someFunc('my variable!'); }).then(function(returnVal) { return console.log(returnVal); }).catch(function(err) { return console.log(err); });
yield
.Copromise is a possible coroutine value. Where a coroutine is a generator function that uses the yield
keyword to pause the launch and wait for a future value. This approach allows to obtain linear control of execution logic (following) for asynchronous code.
function run(coroutine) { return new Promise(function(resolve, reject) { (function next(value, exception) { var result; try { result = exception ? coroutine.throw(value) : coroutine.next(value); } catch (error) { return reject(error); } if (result.done) return resolve(result.value); Promise.resolve(result.value).then(next, function(error) { next(error, true); }); })(); }); }
var app = require('apper')({ path: '.', port: 8000, host: '0.0.0.0', // Not commonly used. Just use `apper.json` for the configuration toOpenBrowser: false, staticContentName: 'public', moduleNames: { environment: 'environment' middleware: 'middleware', routes: 'routes', sockets: 'sockets' }, mountPath: '' }); app.start();
module.exports = function (app) { app.use(function (req, res, next) { // middleware code next(); }); };
app.js
file.Source: https://habr.com/ru/post/236481/
All Articles