V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yazinnnn
V2EX  ›  Kotlin

[协程递归问题请教]

  •  
  •   yazinnnn · 2020-11-18 21:43:07 +08:00 · 2553 次点击
    这是一个创建于 1225 天前的主题,其中的信息可能已经有所发展或是发生改变。

    拿实际业务说 以钉钉接口中的跟部门 id [ 1 ] 为开始,递归出公司详细的组织架构

    
    suspend fun getDepart(){
    	fun getSubDepart(pid):List<Department>{
    		val subList:List<departId> = dingApi.getSubDepartList(pid)
    		return subList.map{
    			Department(it,getSubDepart(it))
    		}
    	}
    	return Department(1,getSubDepart(1))
    }
    
    data class Department(val departId,val subList:List<Department>) //sublist 是下属部门列表 
    
    
    

    业务大概如此描述,同步状态下很简单,请问协程要怎么实现呢?

    我用 withcontext ()包裹追钉钉 api,结果 build 时无法通过,报 call to 'resume' before 'invoke' with coroutine

    请问有大佬能帮助一下吗?

    1 条回复    2020-11-19 09:45:13 +08:00
    hongch
        1
    hongch  
       2020-11-19 09:45:13 +08:00
    exception 贴全一点。。。 还少了几个关键词吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3252 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:10 · PVG 21:10 · LAX 06:10 · JFK 09:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.