-
-
Save KoryNunn/b05b4028ef3825423010eb73489dde11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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