Class: BasicObject
- Defined in:
- opal/stdlib/await.rb
Instance Method Summary
collapse
Instance Method Details
#instance_exec_await(*args, &block) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'opal/stdlib/await.rb', line 82
def instance_exec_await(*args, &block)
::Kernel .raise ::ArgumentError, 'no block given' unless block
# The awaits are defined inside an x-string. Opal can't find them
# reliably and async-ify a method. Therefore, let's make Opal know
# this is an async method.
nil.__await__
%x{
var block_self = block.$$s,
result;
block.$$s = null;
if (self.$$is_a_module) {
self.$$eval = true;
try {
result = await block.apply(self, args);
}
finally {
self.$$eval = false;
}
}
else {
result = await block.apply(self, args);
}
block.$$s = block_self;
return result;
}
end