雖然可用 Future
建立完整的 Cancellable Future,但若想快速建立 Resolved Future,可直接使用 resolve
。
Version
Fluture 14.0.0
resolve
import { resolve, value } from 'Fluture'
import { log } from 'wink-fp'
let data = resolve (1)
let f = value (log)
f (data)
resolve
:將1
包進 Resolved Futurevalue
:從 Resolved Future 內取出內部值由log
顯示
resolve
b -> Future a b
將 value 包進 Resolved Future
b
:傳入 value
Future a b
:回傳 Resolved Future
Conclusion
- 由於
data
只有 Resolved Future,並沒有 Rejected Future,因此可直接使用value
取出,不必使用fork
Reference
Aldwin Vlasbolm, Functional Alternative to Promises
Future, resolve
Future, value