首页 \ 问答 \ 何时应该在Play框架中返回一个Promise而不是实际的结果?(When should a method return a Promise instead of actual result in Play Framework?)

何时应该在Play框架中返回一个Promise而不是实际的结果?(When should a method return a Promise instead of actual result in Play Framework?)

我对Play Framework相对较新。 我正在开发的当前项目中,有大量Promise由服务层组件返回到控制器。 我想知道这是否是最佳做法。 在我看来,使用Promise真的会让消息来源混乱。 而且我必须频繁地使用final修饰符,以使局部变量,参数和类成员可以访问匿名Function我需要为这些Promise创建Function 。 它甚至会影响我创建单元测试用例的方式。 它感到丑陋诚实,并有太多的代码行数超过必要的。 我甚至不确定我们是否做得对,我觉得我们正在过度使用Promise

顺便说一句,我正在使用Java。

那么,我应该什么时候使用Promise ,何时应该返回Promise ,何时不应该使用Promise ? 我们所有的服务和接口都应该返回一个Promise吗? 有没有更好的方法来做到这一点? 请用简单的英语。


I'm relatively new to Play Framework. The current project I'm working on has tons of Promises returned by the service layer components all the way down to controllers. I wonder if that's the best practice. In my opinion, using Promises really clutters up the sources. And I have to make use of final modifiers too frequently just to make local variables, parameters, and class members accessible to anonymous Function I need to create for these Promises. It even affects the way I create my unit test cases. It feels ugly honestly and there's simply too much lines of code than necessary. I'm not even sure if we're doing it right, I feel like we're overusing Promises.

I'm using Java by the way.

So, when should I use a Promise, when should I return a Promise, and when should I not use a Promise? Should all our services and interfaces return a Promise? Is there any better way of doing this? In plain English please.


原文:https://stackoverflow.com/questions/23465951
更新时间:2023-11-12 16:11

最满意答案

应用程序切片目前无法正常工作,直至另行通知。 目前,减少应用规模的唯一方法是减少.ipa中包含的资产数量。

如果它们对您的应用有意义,您可以尝试使用On Demand Resources


Searching app thining, bit code and on demand app resource from yesterday, Now I debug all these things and sharing my knowledge that I got from beautiful apple documentation with help of my sample project.

App thinning concept covers bit code and on-demand resource. I will discuss on-demand resource in detail below:-

On-Demand Resources in iOS:- It is accessing the images/videos/.h/.m/swift file whenever needed (Yes, on-demand resouring include source code files also).

  • Goto Resource tags setting in your target.
  • Create a new Tag. It will appear under Download Only On demand.
  • You can add .h, .m, .xassest, .png etc under various tags. You can also assign tag by selecting individual file like this in file inspector.

Now comes the coding part (my favourite site):-

NSBundleResourceRequest *resourceRequest;


#pragma mark - On demand resource
-(void)getOnDemandResource{
    NSSet *setOfTag = [NSSet setWithObjects:@"chair", nil];
    resourceRequest = [[NSBundleResourceRequest alloc]initWithTags:setOfTag];

    [resourceRequest conditionallyBeginAccessingResourcesWithCompletionHandler:^(BOOL resourcesAvailable) {
        if (!resourcesAvailable) {
//            resourceRequest.loadingPriority = 1;//set the downloading priority (0 - 1) , NSBundleResourceRequestLoadingPriorityUrgent

            [resourceRequest beginAccessingResourcesWithCompletionHandler:^(NSError * _Nullable error) {
                if (error) {
                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.debugDescription preferredStyle:UIAlertControllerStyleAlert];
                    [self presentViewController:alert animated:YES completion:nil];
                }else{
                    //// The associated resources are loaded
                }
            }];
        }else{
            // The associated resources are available
        }
    }];
}

End accessing the on demand resource when not in use(generally when game level changes)

#pragma mark - Remove access to on demand
-(void)endAccessToOnDemandResource{
    [resourceRequest endAccessingResources];
}

NOTE:- Don't forgot to enable On_Demand_Resources in build setting.

EXAMPLE PROJECT:- I create a sample project and uploaded here:- [http://www.dropbox.com/s/edi5zj68a4wuguh/WebOnTab.zip?dl=0][6]

Please don't bother about autolayout in this project. My main focus is on demand resourcing/App thing.

SUMMARY:- Thus we can achieve app thinning by on-demand resourcing using above technique. Please also have a look at official documentation which also describes about tracking progress, priorities of resourceRequests(NSBundleResourceRequest).

相关问答

更多
  • 观看http://vimeo.com/3616452 Watch http://vimeo.com/3616452
  • 应用程序切片目前无法正常工作,直至另行通知。 目前,减少应用规模的唯一方法是减少.ipa中包含的资产数量。 如果它们对您的应用有意义,您可以尝试使用On Demand Resources 。 Searching app thining, bit code and on demand app resource from yesterday, Now I debug all these things and sharing my knowledge that I got from beautiful apple ...
  • 您无需连续检查连接。 您必须在启动需要有效连接的操作之前进行检查。 因此,您不会检入viewDidLoad或其他类。 如果是这种情况,您负责向用户报告连接不可用。 在开始需要连接到Internet的操作之前,请进行检查。 如果连接不可用,请立即通知用户。 在执行检查时可能会发生连接,但在操作期间稍后变得不可用。 你必须小心,在你的代码中包含一个检查。 当您丢失连接时,您需要再次通知用户。 You do not need to check continually the connection. You mus ...
  • 根据App thinning Docs : 注意:对于iOS应用程序,最新的iTunes和运行iOS 9.0及更高版本的设备支持切片应用程序; 否则,App Store会向客户提供通用应用程序。 因此,安装了iOS 7和iOS 8的设备将获得通用版本。 According to App thinning Docs: Note: For iOS apps, sliced apps are supported on the latest iTunes and on devices running iOS 9.0 ...
  • 无论您是否需要保密,您都必须加密并混淆它,以保护自己免受偶然黑客的侵害。 另一方面,我不相信你可以阻止一个坚定的黑客。 越狱,gdb和流量嗅探器的组合将会打败几乎所有你能想到的保护。 大量投资于此类保护措施很少有意义,因此您必须在浪费大量时间和精力并让您的API密钥破解之间找到妥协方案。 就我个人而言,我喜欢在应用程序二进制文件中使用模糊处理API密钥的想法,因为您从App Store获得的二进制文件是加密的。 有PT_DENY_ATTACH的ptrace()小问题可能会使复杂(但绝不会完全阻止)通过gdb ...
  • 我记得有关BuddyPress的一个插件,名为BPDEV XMLRPC,允许您通过XMLRPC与BuddyPress进行通信。 我不知道它是否还没有开发出来,但似乎可以使用它从iPhone应用程序发布消息给BuddyPress。 bp-dev.org目前似乎处于下降状态,但我在那里读到了它。 I remember reading about a plugin for BuddyPress, called BPDEV XMLRPC that allows you to communicate with Bud ...
  • 您应该检查用户的当前语言: NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0]; 然后选择要下载的标签:(现在默认为英文) NSString *tagString = @"english"; if( [language isEqualToString:@"fr"] ){ tagString = @"france"; } else if( [language isEqualToString:@"it"] ){ ...
  • 回答你自己的问题。 归档应用程序。 导出您感兴趣的目标设备的应用程序: 现在查看导出的应用程序内部并查看它包含的资源。 .ipa只是一个.zip文件的另一个名字; 通过更改后缀可以很容易地查看它。 现在您知道iPhone 6 Plus用户将从App Store下载哪些资源。 I performed several additional tests using the procedure proposed by Matt: When minimum deployment target is iOS 6 no ...
  • 如果您仅为新的iPhone 6分辨率添加启动图像(没有新的启动故事板),您仍将获得“针对iPhone 6优化”。 我选择不在我的应用程序中使用启动故事板场景,因为我仍然支持iOS7,这需要启动图像并且不支持启动故事板(iOS 7将简单地忽略启动故事板)。 我的应用程序都说“此应用程序针对iPhone 5,iPhone 6和iPhone 6 Plus进行了优化。” 如果您决定要求iOS 8,则应考虑仅使用启动故事板并删除旧的启动图像。 然后,当新的分辨率设备出来时,您可能不需要更新。 If you add t ...
  • 它绝对是<none> 在Xcode 7中,以下是所有选项的列表: {, , iPad3,1, iPad3,2, iPad3,3, iPad3,4, iPad3,5, iPad3,6, iPad2,3, iPad2,1, iPad2,4, iPad2,2, iPad4,1, iPad4,2, iPad4,3, iPad5,3, iPad5,4, iPad6,7, iPad6,8, iPad6,3, iPad ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)