I was able to get something by doign this
let _ = result -> Js.Promise.then_( val => Js.log(val)->Js.Promise.resolve, _)
I don’t get why I’m supposed to pipe into Js.Promise.resolve. It’s supposed to be resolved when I get the value.!!!
Anyway, I can’t imagine the pain I would have to endure if I was to try to get my fp-ts pipeline into rescript!
const result = pipe(
options,
getUnsubscribed,
TE.map(A.map(somet)),
TE.map(A.sequence(T.taskSeq)),
TE.chain((x) => TE.tryCatch(x, E.toError)),
TE.chainFirstIOK((x) => () => log.info('Items#=', x.length)),
TE.map(A.filter((i) => i.project !== '')),
TE.chainFirstIOK((x) => () => log.info('filter Items#=', x.length)),
TE.map(distinct((i) => i.project + i.email)),
TE.chainFirstIOK((x) => () => log.info('Distinct Items#=', x.length)),
TE.chainW((x) => mapAllUnsubsWithUpdatableInfo(x)),
TE.map(A.filter((x) => x.dbId !== '')),
TE.chainFirstW((unsubsCamp) =>
pipe(
TE.of(unsubsCamp),
TE.chainEitherK(FPJ.stringify),
TE.map((jsonstr) => ',' + jsonstr),
TE.chainIOK(writeFileSync('./contacts-feeds/unsubs.json'))
)
),
TE.fold(
(e) => T.fromIO(() => log.error(opts, e)),
(res) => T.fromIO(() => log.info('done', opts))
)
)()
In my mind, the promise story needs to be sorted out. Why not using a Task or TaskResult abstraction or, even better, an async computation expression a la F#?
Anyway, thanks for the help. That’s appreciated.