I'm playing around with Coldbox futures and was ho...
# box-products
b
I'm playing around with Coldbox futures and was hoping to use it to execute a dozed or so database lookup table queries in parallel. We use a custom DAL that internally makes a reference to a scoped variable in the 'request' context called 'site'. Here is a bit of example code:
Copy code
async().all(
            () => LookupRepository.getCategories()
        ).then( 
            (results) => WriteLog(file='AsyncFutures',text="#serializeJSON(results)#")
        ).onException(
            (results) => WriteLog(file='AsyncFutureErrors',text="#serializeJSON(results)#")
        )
I'm getting an error in the 'AsyncFutureErrors' log about the key 'site' not existing in 'request' scope. Is the current request scope not visible inside of a cbfuture? It'd make sense. Is there a workaround? I'm absolutely new to CB Futures. Thanks.
s
You're right that it follows that a request scope wouldn't be available to an async future. You'd need to pull whatever you wanted out of the request scope and pass it into the async() closure
whatever is in
<http://request.site|request.site>
should be passed into the DAL to maintain encapsulation
b
Thanks. Unfortunately it's not possible to pass it into the DAL due to our app requirements. We'll be looking to cache this information in the near future so it's not a biggy.
b
@bdeline2 place the items to process in a array and process then with map or each with parallel set to true
b
Thanks. I will check that out.