Extracting First Element from Stream in TypeScript Code
i want first element of stream as effect. is this correct?
const result = yield* pipe(
usernameAuthorityService.setUsernamesFor(requests),
Effect.andThen(
flow(
Stream.timeoutFail(() => new SetUsernameForSubmitTimeout({}), Duration.seconds(6)),
Stream.tap(flow(
logUsernameRegistrationEvent,
Effect.annotateLogs({
usernames: unregisteredUsernames.map(({ username }) => username),
}),
)),
Stream.tap((event) => {
if (event.type === 'txBestBlocksState' && !event.found) {
return Effect.fail(new TransactionNotFoundInBestBlockError({ txHash: event.txHash }))
}
return Effect.void
}),
Stream.filter((event) => event.type === 'finalized'),
Stream.map(Effect.succeed),
Stream.catchAll(Effect.fail),
Stream.run(Sink.head()),
Effect.andThen(Effect.orDie),
Effect.flatten
),
),
)const result = yield* pipe(
usernameAuthorityService.setUsernamesFor(requests),
Effect.andThen(
flow(
Stream.timeoutFail(() => new SetUsernameForSubmitTimeout({}), Duration.seconds(6)),
Stream.tap(flow(
logUsernameRegistrationEvent,
Effect.annotateLogs({
usernames: unregisteredUsernames.map(({ username }) => username),
}),
)),
Stream.tap((event) => {
if (event.type === 'txBestBlocksState' && !event.found) {
return Effect.fail(new TransactionNotFoundInBestBlockError({ txHash: event.txHash }))
}
return Effect.void
}),
Stream.filter((event) => event.type === 'finalized'),
Stream.map(Effect.succeed),
Stream.catchAll(Effect.fail),
Stream.run(Sink.head()),
Effect.andThen(Effect.orDie),
Effect.flatten
),
),
)