nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

Nim for TypeScript developers - async edition #15348

Open jonahsnider opened 3 years ago

jonahsnider commented 3 years ago

Summary

This is a documentation only issue.

The Nim for TypeScript Programmers is great but is currently missing information about the similarities between Nim's Futures and TypeScript/JavaScript's Promises, as well as how asynchronous functions behave.

Description

Here is a table I've compiled of Nim asyncfutures features and their respective JavaScript counterparts:

Nim TypeScript/JavaScript
Future[T] Promise<T>
newFuture[T] new Promise<T>()
complete Promise.resolve()
fail Promise.reject()
addCallback Promise.prototype.then()
`and` Promise.all()
`or` Promise.race()
all Promise.all()

Additional Information

The above information only mentions Promises, not any of the behavior with asynchronous functions, which do not behave identically to functions that return a Promise. I don't know enough about Nim's async pragma to write about that.

bung87 commented 3 years ago

hi , if you targeting js you need compare to asyncjs module, it has subset interfaces of asyncfuture, and doesn't support chained promise.that's the major differiences I've found.

dom96 commented 3 years ago

It's a wiki, feel free to modify it :)

narimiran commented 3 years ago

@bung87 @pizzafox interested in making those changes in the wiki? Or maybe @juancarlospaco?

jonahsnider commented 3 years ago

I'm not really comfortable enough with Nim confidently write that kind of documentation. I am however very knowledgeable in TypeScript and would be happy to give more advice on that side of things.