我想等到我的流程完成后再返回我的语音回复,否则它似乎切断了我的流程,因此,没有完成它,我实际上相信它可能会冻结流程,但这不是我的愿望。我该如何等待?@Overridepublic SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) { IntentRequest request = requestEnvelope.getRequest(); Intent intent = request.getIntent(); String intentName = (intent != null) ? intent.getName() : null; if (intentName == null) return null; switch (intentName) { case IntentTitle.NEW_TICKET: switch (request.getDialogState()) { case STARTED: return Response.getDialogueResponse(intent, true); case IN_PROGRESS: return Response.getDialogueResponse(intent, false); case COMPLETED: String numberString = intent.getSlot(SlotTitle.ID).getValue(); if (!NumberUtils.isCreatable(numberString)) return Response.ERROR; Member member = Info.GUILD.getMemberById(numberString); User sender = UserDB.getUser(member); CommissionTicket commissionTicket = new CommissionTicket(sender); commissionTicket.create(); //wait until processes finish before continuing return Response.NEW_TICKED_CREATED; } } return null;}
1 回答
四季花海
TA贡献1811条经验 获得超5个赞
我不确定内部发生了什么commissionTicket.create();(我假设这是您的代码,而不是某个库的一部分,并且它以某种方式异步运行),但一种解决方案是让该方法返回一个Future<>对象,然后等待它完成。类似的东西:
Future<CommissionTicket> commissionTicketFuture = CommissionTicket.create(sender);
commissionTicketFuture.get(SOME_TIMEOUT, TimeUnit.MILLIS);
return Response.NEW_TICKET_CREATED;
添加回答
举报
0/150
提交
取消