是否有任何编译器或运行时支持或计划支持隐式异步编程。
例如
public List<Product> findProductByIdWithSOsAndPOs(int id){
//The next 3 tasks can be done in asynchronously
//task 1.a may take a while
Product product = productRepo.findById(id);
//task 1.b may take a while
List<SalesOrder> salesOrders = salesOrderRepository.findAllByProductId(id);
//task 1.c may take a while
List<PurchaseOrder> purchaseOrders = purchaseOrderRepository.findAllByProductId(id);
//the runtime is smart enough to know that this task depends
//on the previous 3 (1.a, 1.b and 1.c) and won't perform this
//until they are complete without any special syntax (await,
//wrapping in future.map, callbacks, etc.)
//task 2
Product productWithSOsAndPOs = new Product(product.id, product.name, salesOrders, purchaseOrders);
//the runtime is also smart enough until all the tasks are complete
//task 3
return productWithSOsAndPOs;
}
答案 0 :(得分:1)
在.NET中,Tasks.Parallel库使事情变得非常自然。总是有一定程度的语法,但这只是领土。并行编程可能很棘手,编译器无法始终准确地告诉您正在做什么,尤其是涉及多个线程时。在您的数据层上使用Entity Framework可以让事情变得简单,因为异步调用是为您生成的。