-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need tests, docs, and typings for Future #266
Comments
@tshemsedinov Can I take task for adding typings? |
I can also help with writing tests and documentation |
Implementation: @c-0d3-r |
type FutureExecutor = (resolve: Function, reject?: Function) => void;
interface Thenable<T = unknown> {
then(resolve: Resolve<T>, reject: Reject): void;
}
export class Future {
// #1
constructor(executor: FutureExecutor);
// #2
constructor(executor: Function);
static of(value: unknown): Future;
chain(fn: Function): Future;
map(fn: Function): Future;
fork(successed: Function, failed?: Function): void;
toPromise(): Promise<unknown>;
toThenable(): Thenable<unknown>;
}
// #1
type CallbackLastParams = [...params: Array<unknown>, callback: Function];
export function futurify(fn: Function): (...args: CallbackLastParams) => Future;
// #2
export function futurify(fn: Function): (...args: Array<unknown>) => Future;
|
with generics type Resolve<T = unknown> = (value: T) => void;
type Reject = (reason?: Error | unknown) => void;
type Executor<T = unknown> = (resolve: Resolve<T>, reject?: Reject) => void;
interface Thenable<T = unknown> {
then(resolve: Resolve<T>, reject: Reject): void;
}
export class Future<T = unknown> {
static of<U = unknown>(value: U): Future<U>;
constructor(executor: Executor<T>);
chain<U = T>(fn: (value: T) => Future<U>): Future<U>;
map<U = T>(fn: (value: T) => U): Future<U>;
fork(successed: Resolve<T>, failed?: Reject): void;
toPromise(): Promise<T>;
toThenable(): Thenable<T>;
}
type CallbackLastParams = [...args: Array<unknown>, callback: Function];
type CallbackLastFn = (...args: CallbackLastParams) => unknown;
export function futurify(
fn: CallbackLastFn,
): (...args: CallbackLastParams) => Future; |
The first variant looks good, but can you please open a PR for it so i wil be able to edit something. For example And would you like to write a documentation and tests too? Or may I take it? |
@axbuglak Yes, I will open a PR and adjust typings for |
interface Thenable<T = unknown> {
then(resolve: Resolve<T>, reject: Reject): unknown;
} toCallbackLast(): CallbackLastFn;
|
We have implementation moved from https://github.com/HowProgrammingWorks/Future but need tests, docs, and typings as well.
Refs: #260
The text was updated successfully, but these errors were encountered: