react-native-drawing
Version:
A React Native library that provides a canvas to perform drawing actions
53 lines (52 loc) • 1.85 kB
TypeScript
import { Codec } from './Codec';
import { SendDataFunction } from './SendDataFunction';
/**
* A bidirectional manager for Acknowledgement messages
* An ACK is an special message that is provided by other process to indicate an specific status
* @template T - ArgsDTO
* @template U - ResolverData
* @template V - Token
*/
export declare abstract class Ack<T extends Args, U, V extends string> {
private readonly codec;
private readonly sendData;
protected abstract token: V;
private interfaceIndex;
constructor(codec: Codec<T>, sendData: SendDataFunction);
/**
* Uses args to make a choice (resolve or reject ack promise using its interface)
*/
protected abstract makeChoice(args: T, ackInterface: AckInterface<U>): void;
/**
* Verify if the provided data has the strcuture to be shared by the instance
*/
checkData(data: string): data is EncodedData<V>;
/**
* Creates an ACK promise (resolved by another process)
* @param id - Used to identify the ACK message
* (supporting multiple messages at the same time).
* This must be sended by any way to the other process,
* to be sended back with the ack completion (like a calback)
*/
activate(id: number): Promise<U>;
/**
* Reestructures the message data and resolves its ACK (data received by another process)
*/
receive(encodedData: EncodedData<V>): void;
/**
* Send the Ack to another process, it only should be received for a manager with the same structure of that (bidirectional)
*/
send(args: T): void;
}
type EncodedData<T extends string> = `${T}${string}`;
interface Args {
id: number;
}
/**
* Represents the setter for the final status of the message
*/
export interface AckInterface<T> {
resolve(data: T): void;
reject(err: Error): void;
}
export {};