local N=require("\064\068\101\118\080\097\099\107\097\103\101\115\047\074\101\115\116\071\108\111\098\097\108\115")local f=N.describe local u=N.test local p=N.expect local b=require("\046\046\047\105\110\105\116")local E=b.Future f("\112\111\108\108",function()u("\105\109\109\101\100\105\097\116\101",function()local N=E.new(function()return"\097","\098","\099"end)local f=N:poll();(p(f:isReady())).toBe(true)local u=f:unwrap();(p(u:isOk())).toBe(true)local b={u:unwrapOk()};(p(b)).toEqual({"\097","\098","\099"})end)u("\121\105\101\108\100\105\110\103",function()local N=wait local f=E.new(function()N(.1)return"\097","\098","\099"end)local u=f:poll();(p(u:isPending())).toBe(true)N(.1)u=f:poll();(p(u:isReady())).toBe(true)local b=u:unwrap();(p(b:isOk())).toBe(true)local A={b:unwrapOk()};(p(A)).toEqual({"\097","\098","\099"})end)end)
local JestGlobals = require("@DevPackages/JestGlobals")

local describe = JestGlobals.describe
local test = JestGlobals.test
local expect = JestGlobals.expect

local Futures = require("../init")
local Future = Futures.Future

describe("poll", function()
	test("immediate", function()
		local myFuture = Future.new(function()
			return "a", "b", "c"
		end)

		local poll = myFuture:poll()
		expect(poll:isReady()).toBe(true)

		local result = poll:unwrap()
		expect(result:isOk()).toBe(true)

		local values = { result:unwrapOk() }

		expect(values).toEqual({ "a", "b", "c" })
	end)

	test("yielding", function()
		local wait = wait
		local myFuture = Future.new(function()
			wait(0.1)
			return "a", "b", "c"
		end)

		local poll = myFuture:poll()
		expect(poll:isPending()).toBe(true)

		wait(0.1)

		poll = myFuture:poll()
		expect(poll:isReady()).toBe(true)

		local result = poll:unwrap()
		expect(result:isOk()).toBe(true)

		local values = { result:unwrapOk() }

		expect(values).toEqual({ "a", "b", "c" })
	end)
end)
