-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat: add json2md.async method for async converters #32
feat: add json2md.async method for async converters #32
Conversation
adoyle-h
commented
Jan 7, 2018
- json2md.async will return a Promise for asynchronous handle
- json2md.async will return a Promise for asynchronous handle
if (typeof func === "function") { | ||
return Promise.resolve() | ||
.then(() => func(_type ? data : data[type], json2md)) | ||
.then((result) => indento(result, 1, prefix) + "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I'm missing anything, but isn't this still sync
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The func
can be either asynchronous or synchronous function.
For examples:
json2md.converters.md = async (filepath) => {
return await Promise.fromCallback((cb) => FS.readFile(filepath, {encoding: 'utf8'}, cb));
};
json2md.converters.asyncResult = () => Promise.resolve('async');
I love the idea. Thanks for this! However, I'm not sure what async would mean in this case. Just because sync functions are wrapped around in promises, doesn't make them really async. |
Yes, sync functions could be wrapped around in promises. |
Any problems? @IonicaBizau |
Um, I see your point, but in what context would any of the converter functions be async? They are supposed to be small, sync functions. |
I want to read content from file, database, CDN or other services, not only transform content in converter. A part of content may be fetched from the outside of process rather than static variables in codes. For this scenario, the |
Ah, I understand now. 🚀 Can you add some tests before merging? |
OK. It may take a little time. |
@IonicaBizau done. |