I have two functions:
function manipulateData(data,callback)
function isDataValid(data)
The first one is supposed to manipulate the data and return nothing, and the second one is supposed to return true of false depending on the data's structure, without manipulating it at all.
Assuming three things:
-The manipulation doesn't require a valid data.
-The data's validation process is quite demanding IO wise.
-The data's validation process should receive the original data.
How can I use the verification function as the callback argument, so I'd be able to verify it in the background, and only throw an error from the first function, if the data is found invalid?
I want it to behave like this, where the first statement runs in the background and doesn't block the data manipulation.
function manipulateData(data, callback){
if(callback(data)==false){ return some error }
...manipulate data without waiting for the verification...
}
I hope it is indeed doable and that I'm not missing a crucial logical part in the callback mechanism.
via GoldenSpecOps
No comments:
Post a Comment