2016-08-02 3 views

답변

2

구문을 사용하여 연주 한 후 rmunn이 Thenables to Promise를 변환하여 준 단서를 통해 알아낼 수있었습니다.

module PromiseUtils = 
    let success (a : 'T -> 'R) (pr : Promise<'T>) : Promise<'R> = 
     pr?``then`` (unbox a) |> unbox 

    let toPromise (a : Thenable<'T>) = a |> unbox<Promise<'T>> 

    let toThenable (a : Promise<'T>) = a |> unbox<Thenable<'T>> 

위의 유틸리티 모듈을 사용하여 Thenables to Promises를 반환하는 함수를 변환하여 다시 작성할 수있었습니다.

let result = commands.getCommands() 
       |> PromiseUtils.toPromise 
       |> PromiseUtils.success (fun item -> 
        let firstOne = item.Item 1 
        console.log(firstOne)) 
2

이 Ionide가 수행 방법에 대해 살펴 보자 : 여기

이 vscode에 대한 API의 대부분의 예입니다 Ionide 거의 무시처럼 기본적으로

https://github.com/ionide/ionide-vscode-helpers/blob/fable/Helpers.fs https://github.com/ionide/ionide-vscode-helpers/blob/fable/Fable.Import.VSCode.fs

를, 그것은 본다 Thenable<T>이 존재하고 각 API 호출을 Fable 바인딩의 Promise<T>으로 변환합니다. 그들은 toPromisetoThenable의 한 쌍을 Helpers.fs에 가지고 있지만 전체 https://github.com/ionide/ionide-vscode-fsharp 저장소에서 사용되는 것을 보지 못합니다.

개인적으로 우화에 대한 개인적인 경험이 없으므로 질문에 답변이 충분하지 않으면 다른 사람이 더 많은 정보를 제공합니다.

+0

그래, 나는 그 예를 보았습니다. 그러나 유형이 일치하지 않기 때문에 약속이 실제로 해결되는 방법을 실제로 보지 못했습니다 (사용하지 않는다고 언급 한 것처럼). 나는 뭔가를 놓치고 있어야합니다. – Korbin