Skip to content

Commit

Permalink
fix(io): update typings for IO.from()
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Apr 21, 2019
1 parent abe9db2 commit b4ed470
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/main/IO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {Race} from '../operators/Race'
import {OR, Zip} from '../operators/Zip'
import {Computation} from '../sources/Computation'
import {Timeout} from '../sources/Timeout'
import {AnyEnv} from '../envs/AnyEnv'

const NOOP = () => {}
const RETURN_NOOP = () => NOOP
Expand Down Expand Up @@ -117,14 +118,9 @@ export class IO<R1, A1> implements FIO<R1, A1> {
* In most cases you should use [encase] [encaseP] etc. to create new IOs.
* `from` is for more advanced usages and is intended to be used internally.
*/
public static from<A>(
cmp: (
env: SchedulerEnv,
rej: REJ,
res: RES<A>,
sh: IScheduler
) => Cancel | void
): IO<SchedulerEnv, A> {
public static from<R = AnyEnv, A = never>(
cmp: (env: R, rej: REJ, res: RES<A>, sh: IScheduler) => Cancel | void
): IO<R, A> {
return IO.to(new Computation(cmp))
}

Expand Down
2 changes: 1 addition & 1 deletion test/Once.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('OnceCache', () => {
const createRejectingOnceIO = (n: number) => {
let count = 0
const io = new Once(
IO.from<never>((env, rej, res, sh) =>
IO.from((env, rej, res, sh) =>
sh.delay(() => rej(new Error('FAILED_' + (count += 1).toString())), n)
)
)
Expand Down
4 changes: 2 additions & 2 deletions test/Race.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ describe('race', () => {
})
it('should cancel the second io on resolution of one', async () => {
let cancelled = 0
const a = IO.from<never>(() => () => (cancelled = cancelled + 1))
const a = IO.from(() => () => (cancelled = cancelled + 1))
const b = IO.of(100)
const result = await a.race(b).toPromise({scheduler: testScheduler()})
assert.equal(result, 100)
assert.equal(cancelled, 1)
})
it('should cancel the second io on rejection of one', async () => {
let cancelled = 0
const a = IO.from<never>(() => () => (cancelled = cancelled + 1))
const a = IO.from(() => () => (cancelled = cancelled + 1))
const b = IO.reject(new Error('YO'))
const message = await a
.race(b)
Expand Down
4 changes: 2 additions & 2 deletions test/Zip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('zip', () => {

it('should cancel the second io if one of them is rejected', async () => {
let cancelled = 0
const a = IO.from<never>(() => () => (cancelled = cancelled + 1))
const a = IO.from(() => () => (cancelled = cancelled + 1))
const b = IO.reject(new Error('Waka'))
const err = await a
.zip(b)
Expand All @@ -42,7 +42,7 @@ describe('zip', () => {

it('should cancel the second io if one of them is rejected (TEST_SCHEDULER)', async () => {
let cancelled = 0
const a = IO.from<never>(() => () => (cancelled = cancelled + 1))
const a = IO.from(() => () => (cancelled = cancelled + 1))
const b = IO.from((env, rej, res, sh) =>
sh.delay(() => rej(new Error('Save Me!')), 100)
)
Expand Down

0 comments on commit b4ed470

Please sign in to comment.