@@ -65,6 +65,27 @@ local is_eff_obj = function(obj)
65
65
return type (obj ) == " table" and (obj .cls == Eff .cls or obj .cls == Resend .cls )
66
66
end
67
67
68
+ local function get_effh (eff , effeffhs )
69
+ eff = tostring (eff )
70
+
71
+ for i = 1 , # effeffhs do
72
+ if tostring (effeffhs [i ][1 ]) == eff then
73
+ return effeffhs [i ][2 ]
74
+ end
75
+ end
76
+ end
77
+
78
+ local function handle_error_message (r )
79
+ if type (r ) == " string" and
80
+ (r :match (" attempt to yield from outside a coroutine" )
81
+ or r :match (" cannot resume dead coroutine" ))
82
+ then
83
+ return error (" continuation cannot be performed twice" )
84
+ else
85
+ return error (r )
86
+ end
87
+ end
88
+
68
89
local handler
69
90
handler = function (eff , vh , effh )
70
91
local is_the_eff = function (it )
@@ -114,14 +135,7 @@ handler = function(eff, vh, effh)
114
135
continue = function (co , arg )
115
136
local st , r = resume (co , arg )
116
137
if not st then
117
- if type (r ) == " string" and
118
- (r :match (" attempt to yield from outside a coroutine" )
119
- or r :match (" cannot resume dead coroutine" ))
120
- then
121
- return error (" continuation cannot be performed twice" )
122
- else
123
- return error (r )
124
- end
138
+ return handle_error_message (r )
125
139
else
126
140
return handle (r )
127
141
end
@@ -131,16 +145,6 @@ handler = function(eff, vh, effh)
131
145
end
132
146
end
133
147
134
- local function get_effh (eff , effeffhs )
135
- eff = tostring (eff )
136
-
137
- for i = 1 , # effeffhs do
138
- if tostring (effeffhs [i ][1 ]) == eff then
139
- return effeffhs [i ][2 ]
140
- end
141
- end
142
- end
143
-
144
148
local handlers
145
149
handlers = function (vh , ...)
146
150
local effeffhs = {... }
@@ -190,14 +194,7 @@ handlers = function(vh, ...)
190
194
continue = function (co , arg )
191
195
local st , r = resume (co , arg )
192
196
if not st then
193
- if type (r ) == " string" and
194
- (r :match (" attempt to yield from outside a coroutine" )
195
- or r :match (" cannot resume dead coroutine" ))
196
- then
197
- return error (" continuation cannot be performed twice" )
198
- else
199
- return error (r )
200
- end
197
+ return handle_error_message (r )
201
198
else
202
199
return handle (r )
203
200
end
0 commit comments