File tree Expand file tree Collapse file tree 5 files changed +26
-11
lines changed
Expand file tree Collapse file tree 5 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ struct AsyncBaton {
1919template <typename ResultT>
2020struct AsyncBatonWithResult : public AsyncBaton {
2121 ResultT result;
22+ ResultT defaultResult; // result returned if the callback doesn't return anything valid
23+
24+ AsyncBatonWithResult (const ResultT &defaultResult)
25+ : defaultResult(defaultResult) {
26+ }
2227
2328 ResultT ExecuteAsync (uv_async_cb asyncCallback) {
2429 result = 0 ;
Original file line number Diff line number Diff line change 66 {{ arg.cType }} {{ arg.name }}{% if not arg.lastArg %},{% endif %}
77 {% endeach %}
88) {
9- {{ cppFunctionName }}_{{ cbFunction.name |titleCase }}Baton* baton = new {{ cppFunctionName }}_{{ cbFunction.name |titleCase }}Baton ();
9+ {{ cppFunctionName }}_{{ cbFunction.name |titleCase }}Baton* baton =
10+ new {{ cppFunctionName }}_{{ cbFunction.name |titleCase }}Baton ({{ cbFunction.return .noResults }});
1011
1112 {% each cbFunction.args |argsInfo as arg %}
1213 baton->{{ arg.name }} = {{ arg.name }};
@@ -78,12 +79,12 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_async(uv_as
7879 baton->result = (int )result->ToNumber ()->Value ();
7980 }
8081 else {
81- baton->result = {{ cbFunction. return . noResults }} ;
82+ baton->result = baton-> defaultResult ;
8283 }
8384 {% endif %}
8485 }
8586 else {
86- baton->result = {{ cbFunction. return . noResults }} ;
87+ baton->result = baton-> defaultResult ;
8788 }
8889 {% endeach %}
8990
@@ -112,12 +113,12 @@ void {{ cppClassName }}::{{ cppFunctionName }}_{{ cbFunction.name }}_promiseComp
112113 baton->result = (int )result->ToNumber ()->Value ();
113114 }
114115 else {
115- baton->result = {{ cbFunction. return . noResults }} ;
116+ baton->result = baton-> defaultResult ;
116117 }
117118 {% endif %}
118119 }
119120 else {
120- baton->result = {{ cbFunction. return . noResults }} ;
121+ baton->result = baton-> defaultResult ;
121122 }
122123 {% endeach %}
123124 }
Original file line number Diff line number Diff line change 8787 {{ arg.cType }} {{ arg.name }}{% if not arg.lastArg %},{% endif %}
8888 {% endeach %}
8989 ) {
90- {{ field.name |titleCase }}Baton* baton = new {{ field.name |titleCase }}Baton ();
90+ {{ field.name |titleCase }}Baton* baton =
91+ new {{ field.name |titleCase }}Baton ({{ field.return .noResults }});
9192
9293 {% each field.args |argsInfo as arg %}
9394 baton->{{ arg.name }} = {{ arg.name }};
106107
107108 if (instance->{{ field.name }}->IsEmpty ()) {
108109 {% if field.return .type == " int" %}
109- baton->result = {{ field. return . noResults }} ; // no results acquired
110+ baton->result = baton-> defaultResult ; // no results acquired
110111 {% endif %}
111112
112113 baton->done = true ;
172173 baton->result = (int )result->ToNumber ()->Value ();
173174 }
174175 else {
175- baton->result = {{ field. return . noResults }} ;
176+ baton->result = baton-> defaultResult ;
176177 }
177178 {% endif %}
178179 }
179180 else {
180- baton->result = {{ field. return . noResults }} ;
181+ baton->result = baton-> defaultResult ;
181182 }
182183 {% endeach %}
183184 baton->done = true ;
205206 baton->result = (int )result->ToNumber ()->Value ();
206207 }
207208 else {
208- baton->result = {{ field. return . noResults }} ;
209+ baton->result = baton-> defaultResult ;
209210 }
210211 {% endif %}
211212 }
212213 else {
213- baton->result = {{ field. return . noResults }} ;
214+ baton->result = baton-> defaultResult ;
214215 }
215216 {% endeach %}
216217 }
Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ class {{ cppClassName }} : public Nan::ObjectWrap {
6868 {% each arg.args |argsInfo as cbArg %}
6969 {{ cbArg.cType }} {{ cbArg.name }};
7070 {% endeach %}
71+
72+ {{ function.cppFunctionName }}_{{ arg.name |titleCase }}Baton (const {{ arg.return .type }} &defaultResult)
73+ : AsyncBatonWithResult<{{ arg.return .type }}>(defaultResult) {
74+ }
7175 };
7276 {% endif %}
7377 {% endeach %}
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ class {{ cppClassName }} : public Nan::ObjectWrap {
5252 {% each field.args |argsInfo as arg %}
5353 {{ arg.cType }} {{ arg.name }};
5454 {% endeach %}
55+
56+ {{ field.name |titleCase }}Baton (const {{ field.return .type }} &defaultResult)
57+ : AsyncBatonWithResult<{{ field.return .type }}>(defaultResult) {
58+ }
5559 };
5660 {% endif %}
5761 {% endif %}
You can’t perform that action at this time.
0 commit comments