Reputation: 25163
I would like to do something like this in Coffeescript
data = [default, data]
if has_some_data (err, data)-> #has some data hits the db and is a callback
data = data.get_some_data()
process_data()
I would like it so that process data is only called when after the if statement has executed. Is there a good pattern to do this in CoffeeScript?
Upvotes: 1
Views: 68
Reputation: 44349
I'm not super-sure that I'm answering your question, but if your question is "How might I write CoffeeScript that accomplishes this goal?" then...
What about using a callback and errback like so:
data = {...}
callback = (data) -> process_data(data) if data
errback = (err) -> console.log(err)
has_some_data(args, callback, errback)
Otherwise, could you clarify what your constraints are here so I can actually answer your question? ;)
Upvotes: 2