Skip to content

Instantly share code, notes, and snippets.

@nem035
Last active October 19, 2018 18:41
Show Gist options
  • Save nem035/45cfd820a1e4c0292578842dbb7a11c3 to your computer and use it in GitHub Desktop.
Save nem035/45cfd820a1e4c0292578842dbb7a11c3 to your computer and use it in GitHub Desktop.
// when performing an async operation that requires a callback
// we have to immediately provide that callback
// and would need to maintain or pass around a reference to
// the callback in our codebase if we wanted to handle the
// response in a different place from where we started the async
// process.
httpGet(function callback() {
// we have to provide this callback immediately
// when starting this operation and cannot do
// it at a later point.
})
// best we can do to split the async op from our reaction to
// it is to extract the callback as a standalone function.
// Even so, this is just positional separation, not temporal
// or functional. We still maintain a direct reference to our
// async operation => tight coupling
httpGet(callback)
// ... somewhere else
function callback() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment