mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Allow yielding by transfering to nil
This commit is contained in:
		| @@ -359,6 +359,9 @@ int gst_continue(Gst *vm) { | |||||||
|             v1 = stack[pc[3]]; /* The value to pass in */ |             v1 = stack[pc[3]]; /* The value to pass in */ | ||||||
|             if (temp.type != GST_THREAD && temp.type != GST_NIL) |             if (temp.type != GST_THREAD && temp.type != GST_NIL) | ||||||
|                 gst_error(vm, "expected thread"); |                 gst_error(vm, "expected thread"); | ||||||
|  |             if (temp.type == GST_NIL && vm->thread->parent) { | ||||||
|  |                 temp = gst_wrap_thread(vm->thread->parent); | ||||||
|  |             } | ||||||
|             if (temp.type == GST_THREAD) { |             if (temp.type == GST_THREAD) { | ||||||
|                 if (temp.data.thread->status == GST_THREAD_DEAD || |                 if (temp.data.thread->status == GST_THREAD_DEAD || | ||||||
|                     temp.data.thread->status == GST_THREAD_ERROR) |                     temp.data.thread->status == GST_THREAD_ERROR) | ||||||
|   | |||||||
| @@ -80,6 +80,15 @@ | |||||||
| (assert (= athread-result "hello, world!") "thread error result") | (assert (= athread-result "hello, world!") "thread error result") | ||||||
| (assert (= (status athread) "error") "thread error status") | (assert (= (status athread) "error") "thread error status") | ||||||
|  |  | ||||||
|  | "yield tests" | ||||||
|  |  | ||||||
|  | (def t (thread (fn [] (tran nil 1) (tran nil 2) 3))) | ||||||
|  |  | ||||||
|  | (assert (= 1 (tran t)) "initial transfer to new thread") | ||||||
|  | (assert (= 2 (tran t)) "second transfer to thread") | ||||||
|  | (assert (= 3 (tran t)) "return from thread") | ||||||
|  | (assert (= (status t) "dead") "finished thread is dead") | ||||||
|  |  | ||||||
| "report" | "report" | ||||||
|  |  | ||||||
| (print num-tests-passed "of" num-tests-run "tests passed") | (print num-tests-passed "of" num-tests-run "tests passed") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose