Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Forked from sholtomaud/kgo.example.js
Last active January 12, 2019 09:49
Show Gist options
  • Save KoryNunn/b05b4028ef3825423010eb73489dde11 to your computer and use it in GitHub Desktop.
Save KoryNunn/b05b4028ef3825423010eb73489dde11 to your computer and use it in GitHub Desktop.
function update(account, id, schemaData, callback){
schemaData.companyId = account.companyId;
kgo
({
account: account,
id: id,
data: schemaData
})
('updated', ['data'], function(data, done){
db.Schema.update({ _id: id, companyId: account.companyId }, { $set: data, $inc: { version: 1 } }, done);
})
('schema', ['!updated', 'account', 'id'], get)
(['schema'], callback.bind(null, null))
.on('error', function(error){
callback(error);
});
}
var things = righto(function(done){
//Something async
setTimeout(function(){
done(null, 1);
}, 100);
})
var stuff = righto(function(done){
//Something async
setTimeout(function(){
done(null, 2);
}, 100);
})
var whatsits = righto(function(things, stuff, done){
//Something async
setTimeout(function(){
done(null, things + stuff);
}, 100);
}, things, stuff)
var dooby = righto(function(things, done){
//Something async
setTimeout(function(){
done(null, things/2);
}, 100);
}, things)
var result = righto.mate(whatsits, dooby)
result(function(error, whatsits, dooby){
//Done
console.log(whatsits, dooby);
});
var options = righto({
account: account,
id: id,
data: schemaData
})
// Update the schema.
var updated = righto(function(data, done){
db.Schema.update({ _id: id, companyId: account.companyId }, { $set: data, $inc: { version: 1 } }, done);
})
// Get the schema after it is updated.
var schema = righto(get, account, id, righto.after(updated))
// get a result after getting the schema, ignoring the response from schema.
var result = righto.mate(righto.after(schema))
// callback with either error, or nothing.
result(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment