Skip to content

Do notation#22

Open
nythrox wants to merge 4 commits into
tusharmath:masterfrom
nythrox:do-notation
Open

Do notation#22
nythrox wants to merge 4 commits into
tusharmath:masterfrom
nythrox:do-notation

Conversation

@nythrox

@nythrox nythrox commented Oct 16, 2020

Copy link
Copy Markdown

Example:

interface Config {
  port: number
}

const consoleLog = QIO.encase(console.log)
class SpecificError extends Error {
  something!: false
}
class OtherError extends Error {
  smh!: true
}

const getMsg = () =>
  QIO.do(function* () {
    const env = yield* ask<Config>()
    const { name } = yield* ask<{name: string}>()
    if (env.port > 500) {
      yield* QIO.reject(new SpecificError('aha'))
    } else {
      yield* QIO.reject(new OtherError('aha'))
    }
    yield* consoleLog('awaiting...')
    yield* QIO.timeout(void 0, 1000)
    yield* consoleLog('done awaiting!')
    return 'Hello, ' + name
  })
// result: QIO<string, SpecificError | OtherError, Config & { name: string }>
const result = getMsg()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant