-
Notifications
You must be signed in to change notification settings - Fork 21
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
Promise support #14
Comments
Promises? How classic classic ^^ |
Your question was regarding promises right? |
We could discuss it.
@ovi1337 I don't see any benefit in using it instead of a simple |
There are many benefits, you can handle subscriptions, unsubscriptions, debounces, filters, merges, you can collect and share events and many many more things. We're using it since a long time in our company and is very solid. |
No doubts about it, but it's a kinda big framework and I feel like we would introduce too much complexity. We could achieve the same with a simpler eventemitter2 maybe? |
RxJs is completely tree-shakable - it means that only the used functions are injected into the final build, if you're using Webpack, FuseBox or other build tools. But in general i totally agree @ChrisHanuta. In fact of lightweight is the use of Promises much more comfortable instead of the callback hell. |
Yeah but this would require also a bigger dev pipeline to support older versions of node etc. I agree to keep it as slim as possible with a few numbers of dependencies. Supporting Promise wouldn't be too hard to do. The idea could be to keep both callbacks and Promise. |
Hi Guys |
|
I'm ok with promises. Typescript would mean a complete rewrite. |
I'm on a rewrite in typescript and with necessary definitions to use it with comfort, but currently i don't have much time to finish it. I've also rewritten it with a better structure and class typology. |
@roccomuso It is also possible to add a export enum AdsTypeLength {
BOOL = 1,
BYTE = 1,
WORD = 2,
DWORD = 4,
SINT = 1,
USINT = 1,
INT = 2,
UINT = 2,
DINT = 4,
UDINT = 4,
LINT = 8,
ULINT = 8,
REAL = 4,
LREAL = 8,
TIME = 4,
TIME_OF_DAY = 4,
TOD = 4, // TIME_OF_DAY alias
DATE = 4,
DATE_AND_TIME = 4,
DT = 4, // DATE_AND_TIME alias
STRING = 81
}
export enum AdsNotify {
CYCLIC = 3,
ONCHANGE = 4
}
export interface AdsOptions {
host: string
// The NetId of the target machine
amsNetIdTarget: string
// The NetId of the source machine.
// You can choose anything in the form of x.x.x.x.x.x,
// but on the target machine this must be added as a route.
amsNetIdSource: string
// OPTIONAL: (These are set by default)
// The tcp destination port
port?: number | string
// The ams source port
amsPortSource?: number | string
// The ams target port for TwinCat Runtime
amsPortTarget?: number | string
// The timeout for PLC requests
timeout?: number
}
interface AdsHandleInterface {
// Handle name in twincat
symname: string
// An ads type object or an array of type objects.
// You can also specify a number or an array of numbers,
// the result will then be a buffer object.
// If not defined, the default will be BOOL.
bytelength?: AdsTypeLength | AdsTypeLength[]
// The propery name where the value should be written.
// This can be an array with the same length as the array length of byteLength.
// If not defined, the default will be 'value'.
propname?: string | string[]
}
interface AdsNotificationHandleInterface extends AdsHandleInterface {
// OPTIONAL: (These are set by default)
// Notify.ONCHANGE, (other option is Notify.CYCLIC)
transmissionMode?: AdsNotify
// Latest time (in ms) after which the event has finished
maxDelay?: number
// Time (in ms) after which the PLC server checks whether the variable has changed
cycleTime?: number
}
type AdsHandleWithValues<H extends AdsHandleInterface, V extends {}> = H & { [value in keyof V]?: V[value] }
export type AdsHandle<V = {value}> = AdsHandleWithValues<AdsHandleInterface, V>
export type AdsNotificationHandle<V = {value}> = AdsHandleWithValues<AdsNotificationHandleInterface, V>
enum AdsClientEvent {
Error = 'error',
Notification = 'notification'
}
interface AdsClientEventDataMap {
[AdsClientEvent.Error]: Error,
[AdsClientEvent.Notification]: AdsNotificationHandle
}
interface AdsClient {
connect (options: AdsOptions, cb: () => void): void
end (): void
read (handle: AdsHandle, cb: (error: Error, handle: AdsHandle) => void): void
write (handle: AdsHandle, cb: (error: Error) => void): void
getSymbols (cb: (error: Error, symbols: any) => void): void
readState (cb: (error: Error, result: any) => void): void
on<K extends keyof AdsClientEventDataMap> (data: AdsClientEventDataMap[K]): void
} |
The text was updated successfully, but these errors were encountered: