Last active
March 3, 2016 22:02
-
-
Save ahdinosaur/9eadbe426d0c01467439 to your computer and use it in GitHub Desktop.
Enspiral Dev Academy dishwasher instructions
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 runSerial = require('run-serial') | |
var runParallel = require('run-parallel') | |
var createKitchen = require('@eda/kitchen') | |
var lifeskills = require('lifeskills') | |
var kitchen = createKitchen(process.env.KITCHEN) | |
var { dishes, dishwasher, dryingRack } = kitchen | |
function startDishwasher (callback) { | |
runSerial([ | |
lifeskills.addWashPowder(dishwasher), | |
lifeskills.startNormalWash(dishwasher), | |
lifeskills.setLabel(dishwasher, 'CLEAN') | |
], callback) | |
} | |
function emptyDishwasher (callback) { | |
runSerial([ | |
lifeskills.emptyDishwasher(dishwasher), | |
lifeskills.setLabel(dishwasher, 'DIRTY') | |
], callback) | |
} | |
runParallel([ | |
lifeskills.getStatus(dishwasher), | |
lifeskills.getLabel(dishwasher), | |
lifeskills.getContents(dishwasher) | |
], function (err, status, label, contents) { | |
if (err) { return uhOh(err) } | |
var tasks | |
if (label === "CLEAN" && status !== "In Cycle") { | |
tasks = [ | |
emptyDishwasher, | |
lifeskills.loadDishwasher(dishes, dishwasher) | |
] | |
} else if (label === "CLEAN" && status === "In Cycle") { | |
tasks = [ | |
lifeskills.rinseDishes(dishes), | |
lifeskills.stackInDryingRack(dishes, dryingRack) | |
] | |
} else if (label === "DIRTY" && contents === "Full") { | |
tasks = [ | |
lifeskills.loadDishwasher(dishes, dishwasher), | |
startDishwasher | |
] | |
} else if (label === "DIRTY" && contents !== "Full") { | |
tasks = [ | |
lifeskills.rinseDishes(dishes), | |
lifeskills.loadDishwasher(dishes, dishwasher) | |
] | |
} | |
runSerial(tasks, done) | |
function uhOh (err) { | |
lifeskills.repent(err) | |
} | |
function done (err) { | |
if (err) { return uhOh(err) | |
lifeskills.rejoice() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yesssssss. This is on the wall. It's going to be a great teaching example.