/*!
* Copyright (c) 2017-2018 by The Funfix Project Developers.
* Some rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* @flow */
import type { HK, Monad } from "funland"
import type { Throwable } from "funfix-core"
import { Either, Try, Option } from "funfix-core";
import { ICancelable, StackedCancelable, Scheduler, Future, ExecutionModel, Duration } from "funfix-exec";
declare export class IO<+A> {
run(ec?: Scheduler): Future;
runOnComplete(cb: (result: Try) => void, ec?: Scheduler): ICancelable;
attempt(): IO>;
asyncBoundary(ec?: Scheduler): IO;
chain(f: (a: A) => IO): IO;
delayExecution(delay: number | Duration): IO;
delayResult(delay: number | Duration): IO;
doOnFinish(f: (e: Option) => IO): IO;
doOnCancel(callback: IO): IO;
flatMap(f: (a: A) => IO): IO;
ap(ff: IO<(a: A) => B>): IO;
followedBy(fb: IO): IO;
forEach(cb: (a: A) => void): IO;
forEffect(fb: IO): IO;
executeForked(ec?: Scheduler): IO;
executeWithModel(em: ExecutionModel): IO;
executeWithOptions(set: IOOptions): IO;
map(f: (a: A) => B): IO;
memoize(): IO;
memoizeOnSuccess(): IO;
recover(f: (e: Throwable) => AA): IO;
recoverWith(f: (e: Throwable) => IO): IO;
timeout(after: number | Duration): IO;
timeoutTo(after: number | Duration, fallback: IO): IO;
transform(failure: (e: Throwable) => R, success: (a: A) => R): IO;
transformWith(failure: (e: Throwable) => IO, success: (a: A) => IO): IO;
+_tag: "pure" | "always" | "once" | "flatMap" | "async" | "memoize";
static +_Class: IO;
static always(thunk: () => A): IO;
static async(register: (ec: Scheduler, cb: (a: Try) => void) => ICancelable | void): IO;
static asyncUnsafe(register: IORegister): IO;
static defer(thunk: () => IO): IO;
static deferAction(f: (ec: Scheduler) => IO): IO;
static deferFuture(thunk: () => Future): IO;
static deferFutureAction(f: (ec: Scheduler) => Future): IO;
static delayedTick(delay: number | Duration): IO;
static firstCompletedOf(list: Iterable>): IO;
static fromFuture(fa: Future): IO;
static fromTry(a: Try): IO;
static fork(fa: IO, ec?: Scheduler): IO;
static map2(fa1: IO, fa2: IO, f: (a1: A1, a2: A2) => R): IO;
static map3(fa1: IO, fa2: IO, fa3: IO, f: (a1: A1, a2: A2, a3: A3) => R): IO;
static map4(fa1: IO, fa2: IO, fa3: IO, fa4: IO, f: (a1: A1, a2: A2, a3: A3, a4: A4) => R): IO;
static map5(fa1: IO, fa2: IO, fa3: IO, fa4: IO, fa5: IO, f: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R): IO;
static map6(fa1: IO, fa2: IO, fa3: IO, fa4: IO, fa5: IO, fa6: IO, f: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => R): IO;
static now(value: A): IO;
static of(thunk: () => A): IO;
static once(thunk: () => A): IO;
static parMap2(fa1: IO, fa2: IO, f: (a1: A1, a2: A2) => R): IO;
static parMap3(fa1: IO, fa2: IO, fa3: IO, f: (a1: A1, a2: A2, a3: A3) => R): IO;
static parMap4(fa1: IO, fa2: IO, fa3: IO, fa4: IO, f: (a1: A1, a2: A2, a3: A3, a4: A4) => R): IO;
static parMap5(fa1: IO, fa2: IO, fa3: IO, fa4: IO, fa5: IO, f: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R): IO;
static parMap6(fa1: IO, fa2: IO, fa3: IO, fa4: IO, fa5: IO, fa6: IO, f: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => R): IO;
static pure(value: A): IO;
static raise(e: Throwable): IO;
static sequence(list: Iterable>): IO;
static gather(list: Iterable>): IO;
static shift(ec?: Scheduler): IO;
static suspend(thunk: () => IO): IO;
static tailRecM(a: A, f: (a: A) => IO>): IO;
static unit(): IO;
static unsafeStart(source: IO, context: IOContext, cb: (r: Try) => void): void | ICancelable;
}
export type IOURI = (x: [U, L, A]) => IO;
export type IOK = HK;
export type IOTypes = Monad;
declare export var IOModule: IOTypes;
export type IORegister =
(context: IOContext, callback: (result: Try) => void) => void;
declare export class IOContext {
+scheduler: Scheduler;
+connection: StackedCancelable;
+options: IOOptions;
constructor(scheduler: Scheduler, connection?: StackedCancelable, options?: IOOptions): IOContext;
markAsyncBoundary(): void;
shouldCancel(): boolean;
}
export type IOOptions = {
autoCancelableRunLoops: boolean;
};